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.
Efficient way to "re-align" a vector?
eric_pesty
Member Posts: 1,877 PRO
This one is not critical as I figured out ow to get what I wanted... However the method I am using seems very rube goldberg-ish and I am just curious about the "proper" way to do this!
My scenario is that I have an vector defined as "global" x,y,z that I want to use to transform some bodies, however the bodies may be in a different orientation as they are aligned with a reference mate connector.
All I want to do is re-align that vector so that its xAxis is coincident with my mate connector xAxis (I don't actually care about the other axes as they are always zero). I already extracted a coordinate system from my MC. This is what I am doing currently:
So what's the "correct" way of doing this? I did try
My scenario is that I have an vector defined as "global" x,y,z that I want to use to transform some bodies, however the bodies may be in a different orientation as they are aligned with a reference mate connector.
All I want to do is re-align that vector so that its xAxis is coincident with my mate connector xAxis (I don't actually care about the other axes as they are always zero). I already extracted a coordinate system from my MC. This is what I am doing currently:
translatevector = normalize(project(cSys.xAxis, translatevector)) * norm(translatevector); //extra convoluted way of re-aligning vector
So what's the "correct" way of doing this? I did try
translatevector*cSyshoping it would know what to do but that didn't work so I worked around it.
Tagged:
0
Best Answers
-
eric_pesty Member Posts: 1,877 PROUpdate!
Yes, the toWorld(cSys)*translatevector is what I needed to do all along!
In my defense, this is what the documentation says about "toWorld":When used in operations which place or move parts (likeI really don't have any "feel" for how the "*" works with transforms (it seems to work in reverse order to what I would expect as well as apparently being altogether backwards!)opTransform
,opPattern
, oraddInstance
), this transform will (somewhat counterintuitively) move parts from the world origin and orientation to thecSys
origin and orientation.
0 -
EvanReese Member, Mentor Posts: 2,122 ✭✭✭✭✭eric_pesty said:I spoke too soon...
My convoluted method breaks past 90 (offset flips).
And the toWorld way messes things up when I offset the MC, I basically only want the rotation part of the "toWorld" (I think...), to be continued...
Based on this description of your goal...Basically all I want to do is translate my bodies along cSys.xAxis by a distance equal to translatevector.x (which is really the same as the norm of translate vector x and y are both zero).It does seem like you have it right with your original thinking of:[a normalized vector for the direction] * [a length for the distance]
Which might look something like:const translationVector = cSys.xAxis * norm(whateverVectorHasTheLength);
Evan Reese0
Answers
Maybe you need to normalize translatevector.
You could also create a single transform that handles all of the translation and rotation with
Wouldn't the bottom options also modify the entire part studios reference planes?
I'm really not "fluent" in vector math so I'm basically using trial and error (emphasis on error) to get what I need!
Basically all I want to do is translate my bodies along cSys.xAxis by a distance equal to translatevector.x (which is really the same as the norm of translate vector x and y are both zero).
Looking at it now, I think I know where I went wrong!
I actually started with just "translatedistance", then I realized I needed a vector for my opTransform, so I created "translatevector".
It was only much later that I realized I had to realign my vector (when I noticed it didn't work if I rotated my reference mate connector) and I improvised from there until I ended up with this (which seems to work fine):
I think this might actually be the way to do it (based on something I am doing earlier...):
Or can I use it like this:
?
Yes, the toWorld(cSys)*translatevector is what I needed to do all along!
In my defense, this is what the documentation says about "toWorld":
opTransform
,opPattern
, oraddInstance
), this transform will (somewhat counterintuitively) move parts from the world origin and orientation to thecSys
origin and orientation.My convoluted method breaks past 90 (offset flips).
And the toWorld way messes things up when I offset the MC, I basically only want the rotation part of the "toWorld" (I think...), to be continued...
Based on this description of your goal...
[a normalized vector for the direction] * [a length for the distance]
Which might look something like:
Yep, that's it! Thank you!
It makes perfect sense (now that I know the answer...): I know that cSys.xAxis is the direction I want so I just need to make it the length I need!
I think I briefly tried this but gave up when I saw that cSys.xAxis was just (1,0,0) and I thought well that's not helpful... But I think I just hadn't rotated my mate connector at that point (duh)!
It's actually even simpler as the information I have to start with is actually just the distance! So all I need to do is:
and it seems to work as expected at any rotation angle for any offset.
All my ramblings from the last few days was me deciding we can't wait for custom fonts to happen and attempting to crate a feature specifically for the weird font we need to use regularly...
Basically I use a MC for the bottom left corner reference and instantiate a bunch of surfaces (imported from an outside program) corresponding to each character in the string and keeping a running total of how far to move each one to the right (based on the character width and spaces before and after).
The transform is the last step needed to change the justification and I already know the total length from my running total above.
A bit late for images but here's what the baseline case looks like and a center-justified, offset MC, rotated>90deg showing up as intended!