0

What is the way to set and get position of imported STL file. I'm looking for a solution to set position x,y,z to imported STL file like is possible for example to Joint.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Normally things are moved in eyeshot by a transformation matrix. This matrix consists of a rotation matrix 3 x 3, a location 1 x 3, and skew/stretch 4 x 1. All together this makes a 4 x 4 transformation matrix.

an imported stl actually contains lots of locations. But all you need to do is grab one of these. below I have just grabbed the min point of the bounding box.

Then to get to a place create an identity transformation matrix to ensure the rotation and skew are Zero. Now insert your location into the location part of the matrix. The transformBy function will now move every point of the stl to a new location.

to move between points you need the vector difference between the points.

            Mesh myMesh = Mesh.CreateBox(10, 10, 10);
            //Mesh myMesh = new Mesh();

            Point3D getLocation = myMesh.BoxMin;
            Point3D setLocation = new Point3D(20, -10, 0);

            Point3D moveVector = setLocation - getLocation;

            Transformation goPlaces = new Transformation(1);
            goPlaces[0, 3] = moveVector.X;
            goPlaces[1, 3] = moveVector.Y;
            goPlaces[2, 3] = moveVector.Z;

            //Transformation goPlaces = new Transformation(
            //  new double[,]
            //  {
            //      { 1, 0, 0, 20 }, 
            //      { 0, 1, 0,-10 },
            //      { 0, 0, 1,  0 },
            //      { 0, 0, 0,  1 }
            //  }
            //);

            Transformation goBack = (Transformation)goPlaces.Clone();
            goBack.Invert();


            myMesh.TransformBy(goPlaces);

            myMesh.TransformBy(goBack);

Cheers!

Daniel Lord
  • 754
  • 5
  • 18