get FreeCAD.Placement out of two FreeCAD.Vector

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

get FreeCAD.Placement out of two FreeCAD.Vector

Post by bernd »

Assumed I have two FreeCAD.Vector one is the position and the other the direction seen from the position.

How do I get the FreeCAD.Placement out of this. I have been reading Placement twice but still have no glue how to get my Placement in Python.



bernd
mlampert
Veteran
Posts: 1772
Joined: Fri Sep 16, 2016 9:28 pm

Re: get FreeCAD.Placement out of two FreeCAD.Vector

Post by mlampert »

Placement is position and rotation. You seem to have the position but I'm not sure what you mean by
bernd wrote: Sun Jul 21, 2019 10:30 pm ... the direction seen from the position.
Could you elaborate on that a bit ?
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: get FreeCAD.Placement out of two FreeCAD.Vector

Post by bernd »

eventually I need a linear lattice2 placement:

Code: Select all

# generate placements with lattice2
# linear
import lattice2LinearArray, lattice2Executer
la = lattice2LinearArray.makeLinearArray(name='LinearArray')
la.GeneratorMode = 'StepN'
la.Alignment = 'Justify'  # https://forum.freecadweb.org/viewtopic.php?f=22&t=37657#p320586
la.SpanEnd = 1500
la.Step = 200
la.MarkerSize = 100
lattice2Executer.executeFeature(la)
the above one generates a linear lattice2 placement in direction of x starting from 0,0,0 because the obj has standard global placement

As an example I have the following list ... (assumed a check if they are all on a line and have the same step has been done.)

Code: Select all

[Vector (0.0, 0.0, 0.0), Vector (-100.0, 0.0, 0.0), Vector (-200.0, 0.0, 0.0), Vector (-300.0, 0.0, 0.0), Vector (-400.0, 0.0, 0.0), Vector (-500.0, 0.0, 0.0)]

Code: Select all

origin = FreeCAD.Vector(0, 0, 0)
direction = FreeCAD.Vector(-500.0, 0.0, 0.0)
this I need to set the global placement of the lattice2 linear placement with. But how do I get the rotation from the direction
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: get FreeCAD.Placement out of two FreeCAD.Vector

Post by bernd »

DeepSOIC wrote: ping
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: get FreeCAD.Placement out of two FreeCAD.Vector

Post by microelly2 »

There is a Rotation constructor which uses 3 directions
in your case X is your direction
Z may be 0,0,1( keep Head on top)

''' three vectors that define rotated axes directions + an optional 3-characher string of capital letters 'X', 'Y', 'Z' that sets the order of importance of the axes (e.g., 'ZXY' means z direction is followed strictly, x is used but corrected if necessary, y is ignored) '''
return Rotation(X,Y,Z,mode)
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: get FreeCAD.Placement out of two FreeCAD.Vector

Post by DeepSOIC »

microelly2 wrote: Mon Jul 22, 2019 8:09 am There is a Rotation constructor which uses 3 directions
Yes.

Specifically

Code: Select all

dir = App.Vector(1,2,3)
App.ActiveDocument.LinearArray.Placement = App.Placement(App.Vector(), App.Rotation(dir,App.Vector(),App.Vector(0,0,1),"XZY"))
LinearArray also has Dir property, which can be manipulated instead of placement.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: get FreeCAD.Placement out of two FreeCAD.Vector

Post by bernd »

DeepSOIC wrote: Mon Jul 22, 2019 12:31 pm Specifically

Code: Select all

dir = App.Vector(1,2,3)
App.ActiveDocument.LinearArray.Placement = App.Placement(App.Vector(), App.Rotation(dir,App.Vector(),App.Vector(0,0,1),"XZY"))
LinearArray also has Dir property, which can be manipulated instead of placement.
somehow I missed this. :oops:


But still I do some misstakes, more work needs to be done to understand what is happening ... The planes are somehow turned if I use a linear array. Left is linear array, right is custom placement and an array from the custom placements ...
lattice2.jpg
lattice2.jpg (522 KiB) Viewed 1040 times
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: get FreeCAD.Placement out of two FreeCAD.Vector

Post by DeepSOIC »

You may want to set OrientMode to None. At this moment, it only has effect if the array direction is changed with Dir property, not with Placement; unlikewise, PolarArray supports a lot more options there. This is on my todo list, together with removing Dir property altogether and relying on attachment. (if you worry about your scripts being future-proof, it's all right, as I will keep the old code for the lifetime of Lattice2, it will just be unavailable in GUI)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: get FreeCAD.Placement out of two FreeCAD.Vector

Post by bernd »

DeepSOIC wrote: Mon Jul 22, 2019 3:40 pm You may want to set OrientMode to None.
:D


Screenshot_20190722_181018.png
Screenshot_20190722_181018.png (350.62 KiB) Viewed 1021 times
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: get FreeCAD.Placement out of two FreeCAD.Vector

Post by bernd »

setting the appropriate count was still missing in the last picture ...
Post Reply