[SOLVED] Understanding Rotation & Placement

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
gbroques
Posts: 167
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

[SOLVED] Understanding Rotation & Placement

Post by gbroques »

I need help understanding how rotations and placement works.

Let me provide a simple example and form a question to illustrate what I don't understand.

Consider the following "tower" shape, a cone placed on top of a cylinder in a Std Part (see below screenshot).

The cylinder has a height of 10.

Now, I want to rotate about (0, 0, 10), the center of where the cone meets the cylinder, around the X axis, 5 degrees.

See the following code snippet.

Code: Select all

Draft.rotate([FreeCAD.ActiveDocument.Part], 5.0, FreeCAD.Vector(0.0, 0.0, 10.0), axis=FreeCAD.Vector(1.0, 0.0, 0.0), copy=False)
After performing this rotation, the Y becomes 0.87 mm, and Z becomes 38.05 um (both were previously 0).

These are what I'd like to know how to calculate, or the formula FreeCAD uses to come up with these numbers.

How would I calculate the placement offset after the rotation is performed?

Please help me understand how this works. :)
tower.PNG
tower.PNG (36.52 KiB) Viewed 980 times
rotated-tower.PNG
rotated-tower.PNG (30.27 KiB) Viewed 980 times
Last edited by gbroques on Wed May 12, 2021 4:41 pm, edited 1 time in total.
00001000bit
Posts: 24
Joined: Mon Feb 15, 2021 6:14 pm

Re: Understanding Rotation & Placement

Post by 00001000bit »

You pivoted on the top, so the bottom (where the origin was) moved accordingly. The new offset is simply a result of the rotation being fixed at the end opposite of the origin, instead of rotating around the origin itself.

You know the height of the cylinder (c) and the angle (5 deg or 85 deg, depending on which one you choose), so you can figure out the other dimensions using some simple trig.

The height offset is defined by the side of the triangle "a" which can be figured as sin(85)=a/10
which figures out to: 9.96194698091746 - when subtracted from the original 10, gives you 0.038053019082545

The width offset is defined by the side of the triangle "b" which can be figured as cos(85)=b/10
which figures out to: 0.871557427476581
triangles.png
triangles.png (146.05 KiB) Viewed 943 times

Note: in python, you'll need to convert degrees to radians to use in the sin/cos functions "math.radians(85)"
User avatar
gbroques
Posts: 167
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

Re: Understanding Rotation & Placement

Post by gbroques »

00001000bit wrote: Wed May 12, 2021 4:33 pm You pivoted on the top, so the bottom (where the origin was) moved accordingly. The new offset is simply a result of the rotation being fixed at the end opposite of the origin, instead of rotating around the origin itself.

You know the height of the cylinder (c) and the angle (5 deg or 85 deg, depending on which one you choose), so you can figure out the other dimensions using some simple trig.

The height offset is defined by the side of the triangle "a" which can be figured as sin(85)=a/10
which figures out to: 9.96194698091746 - when subtracted from the original 10, gives you 0.038053019082545

The width offset is defined by the side of the triangle "b" which can be figured as cos(85)=b/10
which figures out to: 0.871557427476581

triangles.png


Note: in python, you'll need to convert degrees to radians to use in the sin/cos functions "math.radians(85)"
Thank you very much for this explanation. It helps immensely!! :D
edwilliams16
Veteran
Posts: 3192
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: [SOLVED] Understanding Rotation & Placement

Post by edwilliams16 »

offset_rot.png
offset_rot.png (37.91 KiB) Viewed 924 times
To make the figure less crowded, I've rotated it by 30 degrees instead of 5 degrees. Call the angle theta. We've rotated our object about the x-axis through C (=Vector(0,0,10)). The original origin of the body moves from O to the point Z along a circular arc. Its new coordinates are (0, OY, YZ)

It is now basic trigonometry:

OY = CZ * sin(theta) = 10 *sin(5 deg) = 0.87155742747 mm
YZ = OC - CZ*cos(theta) = 10 - 10*cos(5 deg) = 0.03805301908 mm

Maybe that is sufficient, but this case was greatly simplified because it only need two dimensions to draw it. The more general case is what is the new location P' of a point P if the body is rotated by theta degrees about an axis parallel to n through a offset center C? Naturally, FreeCAD provides the tools for this.

Code: Select all

P = Vector(Px,Py,Pz)
C = Vector(Cx, Cy, Cz)
n = Vector(nx,ny,nz)
rot = Rotation(n, theta)
Pprime = C + rot.multVec(P - C) 
In the case of P being the origin (zero vector), this simplifies to:

Code: Select all

Oprime = C - rot.multVec(C)
Last edited by edwilliams16 on Wed May 12, 2021 5:10 pm, edited 1 time in total.
User avatar
gbroques
Posts: 167
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

Re: [SOLVED] Understanding Rotation & Placement

Post by gbroques »

edwilliams16 wrote: Wed May 12, 2021 5:04 pm offset_rot.png

To make the figure less crowded, I've rotated it by 30 degrees instead of 5 degrees. Call the angle theta. We've rotated our object about the x-axis through C (=Vector(0,0,10)). The original origin of the body moves from O to the point Z along a circular arc. Its new coordinates are (0, OY, YZ)

It is now basic trigonometry:

OY = CZ * sin(theta) = 10 *sin(5 deg) = 0.87155742747 mm
YZ = OC - CZ*cos(theta) = 10 - 10*cos(5 deg) = 0.03805301908 mm

Maybe that is sufficient, but this case was greatly simplified because it only need two dimensions to draw it. The more general case is what is the new location P' of a point P if the body is rotated by theta degrees about an axis parallel to n through a offset center C? Naturally, FreeCAD provides the tools for this.

Code: Select all

P = Vector(Px,Py,Pz)
C = Vector(Cx, Cy, Cz)
n = Vector(nx,ny,nz)
rot = Rotation(n, theta)
Pprime = C + rot.multVec(P - C) 
Thank you! Exceptional answer as well.

This helps a lot! :)
edwilliams16
Veteran
Posts: 3192
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: [SOLVED] Understanding Rotation & Placement

Post by edwilliams16 »

I've added a section on offset rotations to my Sandbox wiki page. https://wiki.freecadweb.org/Sandbox:Edw ... _rotations
User avatar
gbroques
Posts: 167
Joined: Thu Jan 23, 2020 3:28 am
Location: St. Louis, Missouri

Re: [SOLVED] Understanding Rotation & Placement

Post by gbroques »

edwilliams16 wrote: Wed May 12, 2021 5:37 pm I've added a section on offset rotations to my Sandbox wiki page. https://wiki.freecadweb.org/Sandbox:Edw ... _rotations
Thank you.

This looks like a great resource!
Post Reply