I have a 3D model of a room composed of around 80,000 Vertices, When I import it ,the Model is tilted , I Need to place a camera inside the Center of this room and also Rotate the Camera and move inside it , I need to Rotate the Camera around the Normal vector of this room, A simple solution for putting the Camera at the center of the room is taking the average of the vertices , the problem is finding the Normal Vector of the Mesh .
So To Generalize the Question, if i have a 3d model of a huge number of Vertices roughly representing a shape in this case a Cubuoid, how can I determine the Normal vector for this Shape?
I guess you’re using “normal vector” to refer to the reference frame of a minimal object-oriented bounding box? that is, the “up vector” of your room?
In that case, you want to find the covariance matrix of the mesh vertices, then perform principal component analysis (PCA) on it. This will give you the eigenvectors of the covariance matrix, which are the best-matching axes for your vertex data.
These are good reads on the subject: Principal Component Analysis (PCA) Explained | Built In
http://comp3204.ecs.soton.ac.uk/lectures/pdf/L3-covariance.pdf
Building the covariance matrix is very easy, doing PCA on it isn’t as much. I’d recommend finding a good math library to perform principal component analysis.
1 Like