samedi 1 août 2015

Rotate element so its pointing to a specific point in space

I'm having problems with rotating an element (BoxVisual3D).

We have two spheres. The first one is red, the second one is blue. There is a box element with the same center point as the second sphere.

What I need at this point is to rotate this box visual so that its pointing to the red dot. They are all in the same coordinate system. I've done various calculations, but none of them worked the way I wanted. The objective is to find an universal rotation solution.

A short snippet for element rotation around one of the axis.

RotateTransform3D myRotateTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), RotX));
myRotateTransform.CenterX = Spheres[1].Center.X;
myRotateTransform.CenterY = Spheres[1].Center.Y;
myRotateTransform.CenterZ = Spheres[1].Center.Z;

Transform3DGroup RotGroup = new Transform3DGroup();
RotGroup.Children.Add(myRotateTransform);

Models[0].Transform = RotGroup;

Thanks guys!

Aucun commentaire:

Enregistrer un commentaire