Download

How can I rotate a triangle around it's center?

I have an array of vertex locations. I need to take one of these isosceles triangles and make it’s normal point perfectly along one axis, and it’s forward vertex point along another axis. Currently the triangle is rotated in such a way that it’s normal points towards the worlds center (0,0,0). I’ve tried using:


FRotationMatrix orientationRot = FRotationMatrix(cellRotation);
FVector changedVec = orientationRot.TransformVector(tempVerts*.cellCornerToFVec());

But this appears to rotate the triangle around the worlds center, and while this may still be a way to do it (if I can perfectly swivel the triangle so that its normal is aligned with an axis, and getting the forward vertex to point along another), I’m curious about future situations where I would need to rotate vectors around their triangles center.

You basically need a local transform to ‘Rotate’ the vertices around (I would suggest the center). What I would do is add all the vertex positions (World Space) together and divide by 3 (To get the average or ‘center’ position of them all) and create the transform at that location.

Thanks! I was able to create a transform as the triangles center then get the triangles normal, then subtract the locations of the up vert against the middle location - giving me the up vector for this triangle. Then I

FRotator triRotator = FRotationMatrix::MakeFromZX(trianglenormal, triangleUp).Rotator();

I used this as the Rotator for creating the FTransform. Then I myTriTransform.InverseTransformVector(vertArray*); This plopped each vert to the aligned axis as hoped.

Thanks again!