I am attempting to identify instances of self-intersection in a polygon in order to prevent users from creating them. Users are only permitted to draw the polygon on a plane formed by connecting the coplanar points they plot in 3D space.
My initial approach involved aligning these points parallel to the X-Z plane and then checking for intersections between line segments. While I could successfully detect intersections in 2D, rotating these points did not maintain their shape or alignment with the XZ axis, leading to issues during intersection testing.
Before rotation: https://i.sstatic.net/Yr35i.png
After rotation https://i.sstatic.net/LaFUE.png
This is my current rotation method.
const angle = pos.angleTo(new THREE.Vector3(0, 1, 0)) // pos here represents the position vector of the circle
const rotationMatrix = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(1, 0, 0), -angle); // rotate around x Axis
rotationMatrix.makeRotationAxis(new THREE.Vector3(0, 0, 1), -angle) // rotate around z axis
circle.applyMatrix4(rotationMatrix);
The goal is to rotate the vertices so that they align parallel to the XZ axes without distorting their original shape. As a newcomer to three.js, I believe there may be something crucial missing from my implementation.
How can I accurately rotate the vertices to achieve parallel alignment with the XZ axes while preserving the shape?