If you need to align two planes, you can obtain the transformation needed (which in general is a roto-translation) using:
CreateAlignment(Plane from, Plane to)or
Rotation(Plane plane0, Plane plane1)This allows for instance to superimpose two faces of two meshes like in the following example:
The code to reproduce this example is reported below. In the first part, we create two meshes:
// FIRST MESH
Mesh mesh1 = Mesh.CreateBox(5, 4, 7);
design1.Entities.Add(mesh1, 0, Color.Red);
// SECOND MESH
Mesh mesh2 = Mesh.CreateBox(4, 3, 2);
// we transform mesh2 and move it away from mesh1
mesh2.Rotate(.1, Vector3D.AxisX);
mesh2.Rotate(.5, Vector3D.AxisY);
mesh2.Rotate(1, Vector3D.AxisZ);
mesh2.Translate(new Vector3D(4, 3, 12));
design1.Entities.Add((Mesh)mesh2.Clone(), Color.Blue);
Then we define a transformation that aligns the lower face of mesh2 with the upper face of mesh1. This can be done in two ways:
- Using Transformation.CreateAlignment and the planes
// plane of the upper face of mesh1
Plane plane1 = new Plane(mesh1.Vertices[4], mesh1.Vertices[5], mesh1.Vertices[7]);
// plane of the lower face of mesh2
Plane plane2 = new Plane(mesh2.Vertices[0], mesh2.Vertices[1], mesh2.Vertices[3]);
Transformation rotoTranslation = Transformation.CreateAlignment(plane2, plane1);
- Or using Rotation and the planes
// plane of the upper face of mesh1
Plane plane1 = new Plane(mesh1.Vertices[4], mesh1.Vertices[5], mesh1.Vertices[7]);
// plane of the lower face of mesh2
Plane plane2 = new Plane(mesh2.Vertices[0], mesh2.Vertices[1], mesh2.Vertices[3]);
Transformation rotoTranslation = new Transformation();
rotoTranslation.Rotation(plane2, plane1);
And finally, we apply the transformation to mesh2:
mesh2.TransformBy(rotoTranslation);
design1.Entities.Add((Mesh)mesh2.Clone(), Color.Blue);
Comments
Please sign in to leave a comment.