Actually no, not really enough time for this. But I still think there is something to be improved there.
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!
Re: Position and orientation in the reference frame of a LCS
Hello.
Just to clarify my question. Imagine a simple draft point:
point = Draft.makePoint(X, Y, Z)
then such a point will be at (X,Y,Z) relative to the global reference frame.
Now, imagine a local coordinate system that is at any position and orientation relative to the global coordinate system.
The question is, how can I get the position of the point, but as viewed from the local coordinate system?
I know I can do some simple geometry or a transformed coordinate system for this, but I though FreeCAD may already have this option...
The same applies for the position of the points that define a line.
Just to clarify my question. Imagine a simple draft point:
point = Draft.makePoint(X, Y, Z)
then such a point will be at (X,Y,Z) relative to the global reference frame.
Now, imagine a local coordinate system that is at any position and orientation relative to the global coordinate system.
The question is, how can I get the position of the point, but as viewed from the local coordinate system?
I know I can do some simple geometry or a transformed coordinate system for this, but I though FreeCAD may already have this option...
The same applies for the position of the points that define a line.
Re: Position and orientation in the reference frame of a LCS
Code: Select all
import FreeCAD as App
import Draft
doc = App.newDocument()
p1 = App.Vector(0, 0, 0)
p2 = App.Vector(1000, 500, 0)
line = Draft.make_line(p1, p2)
place = line.Placement
place.rotate(App.Vector(0, 0, 0), App.Vector(1, 1, 1), 35)
doc.recompute()
global_point = place.multVec(line.Points[1])
print(global_point)
local_point = place.inverse().multVec(global_point)
print(local_point)
Re: Position and orientation in the reference frame of a LCS
Hi, RoyRoy_043 wrote: ↑Sun Jul 17, 2022 2:00 pmCode: Select all
import FreeCAD as App import Draft doc = App.newDocument() p1 = App.Vector(0, 0, 0) p2 = App.Vector(1000, 500, 0) line = Draft.make_line(p1, p2) place = line.Placement place.rotate(App.Vector(0, 0, 0), App.Vector(1, 1, 1), 35) doc.recompute() global_point = place.multVec(line.Points[1]) print(global_point) local_point = place.inverse().multVec(global_point) print(local_point)
How to get the global location of an object in a link group? when the link group move, the placement information of objects in the group is not updated.
Re: Position and orientation in the reference frame of a LCS
Your code should determine the cumulative effect of the placements (see Option 1). Part.getShape can also be used, but is less efficient if you do not need the shape it returns (see Option 2).
Code: Select all
import FreeCAD as App
import Part
doc = App.ActiveDocument
prt = doc.Part
grp = doc.LinkGroup
lnk = doc.Link
lin = doc.Line
# Option 1
point = lin.Points[1]
for obj in [lin, lnk, grp, prt]:
point = obj.Placement.multVec(point)
print(point)
# Option 2
shape, matrix, obj = Part.getShape(prt, "LinkGroup.Link", needSubElement=True, retType=2)
place = App.Placement(matrix)
point = lin.Points[1]
point = place.multVec(point)
print(point)
- Attachments
-
- Placement_Test_LinkGroup.FCStd
- (7.39 KiB) Downloaded 46 times
-
- 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
What is the meaning of this error your file generates when clicking on LinkGroup?
Code: Select all
Error adjustedGlobalPlacement
Code: Select all
OS: macOS High Sierra (10.13)
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: (HEAD detached at 0.20)
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.9.13, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods:
* Curves 0.4.4
* DynamicData 2.46.0
* fasteners 0.3.44
* fcgear 1.0.0
* GDML 1.8.0
* Help 1.0.2
* lattice2 1.0.0
* MeshRemodel 1.8919.0
* toSketch
Code: Select all
OS: macOS High Sierra (10.13)
Word size of FreeCAD: 64-bit
Version: 0.21.29393 (Git)
Build type: Release
Branch: master
Hash: 6820e0a9ec85203a6f342ca72a2ff8fd417beaf1
Python 3.10.5, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods:
* Curves 0.4.4
* DynamicData 2.46.0
* fasteners 0.3.44
* fcgear 1.0.0
* GDML 1.8.0
* Help 1.0.2
* lattice2 1.0.0
* MeshRemodel 1.8919.0
* toSketch
Re: Position and orientation in the reference frame of a LCS
I am pretty clueless.edwilliams16 wrote: ↑Fri Jul 22, 2022 11:43 pm What is the meaning of this error your file generates when clicking on LinkGroup?
Code: Select all
Error adjustedGlobalPlacement
I don't get the error with V0.20 either BTW.
Code: Select all
OS: Windows 8.1 Version 6.3 (Build 9600)
Word size of FreeCAD: 64-bit
Version: 0.20.29177 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: 68e337670e227889217652ddac593c93b5e8dc94
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.2
Locale: English/United States (en_US) [ OS: Dutch/Netherlands (nl_NL) ]
Re: Position and orientation in the reference frame of a LCS
I am doing what I think may be the most efficient way to solve this:
Is this correct?
Code: Select all
#Create a placement:
p1 = App.Placement()
#Move to (0,0,1). The "point" is now (0,0,1).
p1.Base = (0,0,1)
#Create a local coordinate system (initially orthonormal to the global coordinate system):
lcs = App.activeDocument().addObject( 'PartDesign::CoordinateSystem', 'LCS' )
#Get the placement of p1 as seen from LCS (same as global placement of p1):
lcs.Placement.inverse().multiply(p1)
#Move and rotate the LCS:
lcs.Placement=App.Placement(App.Vector(0,0,-1), App.Rotation(0,0,90), App.Vector(0,0,0))
#Get the new placement of p1 as seen from the translated and rotated LCS:
lcs.Placement.inverse().multiply(p1)
Re: Position and orientation in the reference frame of a LCS
Is it documented somewhere? is there any API for that? or this is hidden knowledge borrowed from ancient aliens and posted at forum only for chosen? LOL
Thanks
Darek
github.com/dprojects
workbench for woodworking is available at: github.com/dprojects/Woodworking