Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
2. Need support? Ask a question to our Community Support category.
3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
4. 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.

Options

# rotate a vector and points

Member Posts: 113 EDU
hello,
how can I rotate vectors and points around a line with a given angle in FS? (to move them by the angle given)
as opTransform only accepts bodies....

Tagged:

• Options
Onshape Employees, Developers, HDM Posts: 1,187
opTransform is for rotating geometry in the context.  For transforming vectors (and other things like lines and planes) you can just multiply the transform by the point:
var myTransform = rotationAround(myLine, 30 * degree);
var newPoint = myTransform * (vector(1, 2, 3) * meter);
Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
• Options
Member Posts: 113 EDU
edited August 2019
opTransform is for rotating geometry in the context.  For transforming vectors (and other things like lines and planes) you can just multiply the transform by the point:
var myTransform = rotationAround(myLine, 30 * degree);
var newPoint = myTransform * (vector(1, 2, 3) * meter);
i cant succed to make it work....
trying this :(point1 and 2 are previously defined)
var Line1=line(point1,point2);
var transf=rotationAround(X_AXIS,definition.xangle);
var linerotated= transf*Line1;

it needed a unit. thanks!
• Options
Onshape Employees, Developers, HDM Posts: 1,187
Without the specific error (including line number) and the whole feature, it's impossible to debug.  Please post a link to a public document.
Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
• Options
Member Posts: 113 EDU
Without the specific error (including line number) and the whole feature, it's impossible to debug.  Please post a link to a public document.
it is okey, actually when i tried same thing that you told me with vectors, it didnt work, but after i gave them units it worked. so, i solved to translate the points and after do the line.

thanks anyway
• Options
Member Posts: 1
Yes, we can do with a line, but I hope I dont have to create a line only for rotating the entity.
using point and vector would be fantastic.
Thank you.
• Options
Moderator, Onshape Employees Posts: 5,519
Yes, we can do with a line, but I hope I dont have to create a line only for rotating the entity.
using point and vector would be fantastic.
Thank you.
You don’t have to create a physical line - the Line object is a point (with units) and a vector (unitless)
Senior Director, Technical Services, EMEAI
• Options
Member Posts: 109 PRO
edited May 21
for the newbs (like me) ending up on this thread searching how to rotate a direction vector.
I tried

coneAngleRotation = rotationAround(rotationAxis, angle);
normalize(toPlaneNormal = coneAngleRotation * (toPlaneNormal * meter)

in order to rotate the unitless direction vector "toPlaneNormal". This doesn't work because in this multiplication the vector is interpreted as a point rather than a direction. It'll give an outcome, but it depends on the units chosen and isn't what you're intending. So best to create a line and rotate it that way:

coneAngleRotation = rotationAround(rotationAxis, angle);
var toPlaneNormalLine = line(point, toPlaneNormal);
toPlaneNormalLine = coneAngleRotation * toPlaneNormalLine;

toPlaneNormal = toPlaneNormalLine.direction;