Eyeshot 11 Documentation
WinForms Control / Tutorials / Align In 3D
In This Topic
    Align In 3D
    In This Topic

    If you need to align two planes, you can obtain the transformation needed (which in general is a roto-translation) using:

    Align3D(Point3D p1A, Point3D p1B, Point3D p2A, Point3D p2B, Point3D p3A, Point3D p3B);
    Align3D(Plane originalFrame, Plane destinationFrame);
    Align3D(Point3D p1A, Point3D p1B, Point3D p2A, Point3D p2B, Point3D p3A, Point3D p3B)
    Align3D(Plane originalFrame, Plane destinationFrame)

    or

    Rotation(Plane plane0, Plane plane1);             
    Rotation(Plane plane0, Plane plane1)
    
                  

    This allows for instance to superimpose two faces of two meshes like in the following example:

    Before and after.PNG


    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); 
    viewport.Entities.Add(mesh1, 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)); 
    viewport.Entities.Add((Mesh)mesh2.Clone(), Color.Blue);           
    ' FIRST MESH
    Dim mesh1 As Mesh = Mesh.CreateBox(5, 4, 7)
    Viewport.Entities.Add(mesh1, 0, Color.Red)
    
    ' SECOND MESH
    Dim mesh2 As Mesh = Mesh.CreateBox(4, 3, 2)
    
    ' we transform mesh2 and move it away from mesh1
    mesh2.Rotate(0.1, Vector3D.AxisX)
    mesh2.Rotate(0.5, Vector3D.AxisY)
    mesh2.Rotate(1, Vector3D.AxisZ)
    mesh2.Translate(New Vector3D(4, 3, 12))
    Viewport.Entities.Add(DirectCast(mesh2.Clone(), Mesh), 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 three different ways:

    Transformation rotoTranslation = new Align3D(mesh2.Vertices[0], mesh1.Vertices[4],  
                                                 mesh2.Vertices[1], mesh1.Vertices[5],  
                                                 mesh2.Vertices[3], mesh1.Vertices[7]);           
    Dim rotoTranslation As Transformation = New Align3D(mesh2.Vertices(0), mesh1.Vertices(4), 
                                    mesh2.Vertices(1), mesh1.Vertices(5), 
                                mesh2.Vertices(3), mesh1.Vertices(7))
    // 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 Align3D(plane2, plane1);              
    ' plane of the upper face of mesh1
    Dim plane1 As New Plane(mesh1.Vertices(4), mesh1.Vertices(5), mesh1.Vertices(7))
    ' plane of the lower face of mesh2
    Dim plane2 As New Plane(mesh2.Vertices(0), mesh2.Vertices(1), mesh2.Vertices(3))
    
    Dim rotoTranslation As Transformation = New Align3D(plane2, plane1)
    // 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);                
    ' plane of the upper face of mesh1
    Dim plane1 As New Plane(mesh1.Vertices(4), mesh1.Vertices(5), mesh1.Vertices(7))
    ' plane of the lower face of mesh2
    Dim plane2 As New Plane(mesh2.Vertices(0), mesh2.Vertices(1), mesh2.Vertices(3))
    
    Dim rotoTranslation As New Transformation()
    rotoTranslation.Rotation(plane2, plane1)


    And finally we apply the transformation to mesh2:

    mesh2.TransformBy(rotoTranslation); 
    
    viewport.Entities.Add((Mesh)mesh2.Clone(), Color.Blue); 
    mesh2.TransformBy(rotoTranslation)
    
    Viewport.Entities.Add(DirectCast(mesh2.Clone(), Mesh), Color.Blue)