Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
opMoveFace distance & direction?
MichaelPascoe
Member Posts: 2,012 PRO
I'm trying to move a face 1" in the direction of the zAxis of the csys that I created. What I have now moves it 1" from the world origin... How do I do this?
opMoveFace(context, id + "moveFace1", { "moveFaces" : faceToMove[5], "transform" : transform(-toWorld(selectedCoordinateSystem, vector(0, 0, 1) * inch)) });
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Tagged:
0
Best Answer
-
Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646@MichaelPascoe
You could just use this overload of `transform`:
https://cad.onshape.com/FsDoc/library.html#transform-Vector
which takes a translation vector. Then your transform would just be:transform(zAxis(selectedCoordinateSystem) * (1 * inch))
When passing a transformation into interfaces like this, it is helpful to keep in mind that what is happening is:
eachResultPoint = givenTransformation * eachPointOnTheInputGeometry
the key here being that the input points are multiplied on the right of each transform (which can be thought of as a matrix). So if you give multiple transforms, it is:
eachResultPoint = xformA * xformB * xformC * eachPointOnTheGeometry
With this in mind an appropriate way to do the transformation that you want, but for any arbitrary translation in the selected coordinate system, would be:const selectedCSys = ... your coordinate system const translationInSelectedCSys = ... a translation that you want to occur, in the reference frame of `selectedCSys` const xform = toWorld(selectedCSys) * transform(translationInSelectedCSys) * fromWorld(selectedCSys); opMoveFace(..., {..., "transform" : xform});
What this transform does (reading right-to-left as described above), is take each point on the desired face, apply a fromWorld to change the point from world space coordinates to selectedCSys coordinates, apply the desired translation, then apply a toWorld to change the point from selectedCSys coordinates back to world space coordinates.
Let me know if you have additional questions.Jake Rosenfeld - Modeling Team5
Answers
You could just use this overload of `transform`:
https://cad.onshape.com/FsDoc/library.html#transform-Vector
which takes a translation vector. Then your transform would just be:
When passing a transformation into interfaces like this, it is helpful to keep in mind that what is happening is:
eachResultPoint = givenTransformation * eachPointOnTheInputGeometry
the key here being that the input points are multiplied on the right of each transform (which can be thought of as a matrix). So if you give multiple transforms, it is:
eachResultPoint = xformA * xformB * xformC * eachPointOnTheGeometry
With this in mind an appropriate way to do the transformation that you want, but for any arbitrary translation in the selected coordinate system, would be:
What this transform does (reading right-to-left as described above), is take each point on the desired face, apply a fromWorld to change the point from world space coordinates to selectedCSys coordinates, apply the desired translation, then apply a toWorld to change the point from selectedCSys coordinates back to world space coordinates.
Let me know if you have additional questions.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴