Position and orientation in the reference frame of a LCS

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
josegegas
Posts: 255
Joined: Sat Feb 11, 2017 12:54 am
Location: New Zealand

Position and orientation in the reference frame of a LCS

Post by josegegas »

Hi.

Is there a way to get the position and orientation of, say, a point and a line, respectively, in the reference frame of a local coordinate system?
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: Position and orientation in the reference frame of a LCS

Post by chrisb »

As nobody answered until now, I can show you a rather complicated non parametric workaround:
- create a ShapeBinder of the global object
- set TraceSupport=True
- attach something to the ShapeBinder
- detach it

-> now the formerly attached object has the placement in local coordinates of the global object
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Position and orientation in the reference frame of a LCS

Post by openBrain »

josegegas wrote: Mon Jan 31, 2022 2:33 pm Hi.

Is there a way to get the position and orientation of, say, a point and a line, respectively, in the reference frame of a local coordinate system?
Is Python scripting allowed ? For better understanding, please provide sample file with said point, line & LCS ;)
josegegas
Posts: 255
Joined: Sat Feb 11, 2017 12:54 am
Location: New Zealand

Re: Position and orientation in the reference frame of a LCS

Post by josegegas »

I am no talking about using the GUI, but Python. Imagine I create a local coordinate system at any given position and orientation. Then I want to get the coordinates of any point (or another LCS), not relative to the global coordinate system, but relative to the first LCS. It would also be great if it was possible to get the orientation of a given line, again, not relative to the global coordinate system, but relative to the LCS...

So far I have been using Sympy for these purposes:

https://docs.sympy.org/latest/modules/v ... rdsys.html

As you can see Sympy allows creating coordinate systems that are translated and rotated relative to one another, and then obtaining the relative positions and orientations as seen from any coordinate system. I would like to know if it is possible to do the same using FreeCAD, and I though local coordinate systems may allow so.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Position and orientation in the reference frame of a LCS

Post by openBrain »

josegegas wrote: Tue Feb 01, 2022 2:23 pm I am no talking about using the GUI, but Python. Imagine I create a local coordinate system at any given position and orientation. Then I want to get the coordinates of any point (or another LCS), not relative to the global coordinate system, but relative to the first LCS.
If I get it correctly, it's as simple as :

Code: Select all

LCS.getGlobalPlacement().inverse().multiply(OBJ.getGlobalPlacement())
chrisb
Veteran
Posts: 54201
Joined: Tue Mar 17, 2015 9:14 am

Re: Position and orientation in the reference frame of a LCS

Post by chrisb »

josegegas wrote: Tue Feb 01, 2022 2:23 pm I am no talking about using the GUI, but Python.
Moved to Python forum.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
galou_breizh
Posts: 437
Joined: Wed Sep 15, 2010 9:38 am

Re: Position and orientation in the reference frame of a LCS

Post by galou_breizh »

josegegas wrote: Tue Feb 01, 2022 2:23 pm If I get it correctly, it's as simple as :

Code: Select all

LCS.getGlobalPlacement().inverse().multiply(OBJ.getGlobalPlacement())
Beware! This is misleading as getGlobalPlacement does not work for links (it shows the global placement of the original object). See the GetGlobalPlacement macro for a version supporting links.

Gaël
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Position and orientation in the reference frame of a LCS

Post by openBrain »

galou_breizh wrote: Fri Feb 04, 2022 8:33 am Beware! This is misleading as getGlobalPlacement does not work for links (it shows the global placement of the original object). See the GetGlobalPlacement macro for a version supporting links.
Why not fixing the code ?
edwilliams16
Veteran
Posts: 3180
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Position and orientation in the reference frame of a LCS

Post by edwilliams16 »

openBrain wrote: Fri Feb 04, 2022 5:27 pm
galou_breizh wrote: Fri Feb 04, 2022 8:33 am Beware! This is misleading as getGlobalPlacement does not work for links (it shows the global placement of the original object). See the GetGlobalPlacement macro for a version supporting links.
Why not fixing the code ?
It does seem like a bug/deficiency. A linked object either has no getGlobalPlacement() method, or the method returns the global placement of the original, not the linked object. The global placement can be obtained by multiplying up the placements of the chain of objects starting at the root, as described in the https://forum.freecadweb.org/viewtopic.php?f=22&t=64608 thread and nicely implemented by @galou_breizh in his macro.
It makes the method less useful when you need to write your own if you want it to apply to linked objects.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Position and orientation in the reference frame of a LCS

Post by openBrain »

edwilliams16 wrote: Sat Feb 05, 2022 2:26 am It does seem like a bug/deficiency. A linked object either has no getGlobalPlacement() method, or the method returns the global placement of the original, not the linked object.
Looks like something that can be very improved IMO. A link object should return its global placement when 'getGlobalPlacement' is called on it. No reason to return something else. ;)
Post Reply