Position and orientation in the reference frame of a LCS
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Position and orientation in the reference frame of a LCS
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 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?
Re: Position and orientation in the reference frame of a LCS
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
- 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.
Re: Position and orientation in the reference frame of a LCS
Is Python scripting allowed ? For better understanding, please provide sample file with said point, line & LCS
Re: Position and orientation in the reference frame of a LCS
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.
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.
Re: Position and orientation in the reference frame of a LCS
If I get it correctly, it's as simple as :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.
Code: Select all
LCS.getGlobalPlacement().inverse().multiply(OBJ.getGlobalPlacement())
Re: Position and orientation in the reference frame of a LCS
Moved to Python forum.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
-
- Posts: 437
- Joined: Wed Sep 15, 2010 9:38 am
Re: Position and orientation in the reference frame of a LCS
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.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())
Gaël
Re: Position and orientation in the reference frame of a LCS
Why not fixing the code ?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.
-
- 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
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.openBrain wrote: ↑Fri Feb 04, 2022 5:27 pmWhy not fixing the code ?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.
It makes the method less useful when you need to write your own if you want it to apply to linked objects.
Re: Position and orientation in the reference frame of a LCS
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.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.