placement transformation

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:

placement transformation

Post by bernd »

Assumed:
- two identical wire
- made only from straight edges
- same start point
- the rest could be some how turned in 3D orbit

I would like to somehow save what is needed to move and turn one wire into the other. As input I only have the shapes of the wire.

Someone know how to do this?
User avatar
Chris_G
Veteran
Posts: 2602
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: placement transformation

Post by Chris_G »

This should do it :

Code: Select all

def get_relative_placement(shape1, shape2):
    "returns the placement that must be applied to shape1 to move it to shape_2"
    plane1 = Part.Plane(*[v.Point for v in shape1.Vertexes[0:3]])
    plane2 = Part.Plane(*[v.Point for v in shape2.Vertexes[0:3]])
    pl1 = FreeCAD.Placement(plane1.Position, plane1.Rotation)
    pl2 = FreeCAD.Placement(plane2.Position, plane2.Rotation)
    return pl2.multiply(pl1.inverse())
Assuming that the first 3 vertexes of the shape correctly define a plane (not coincident, nor colinear)
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: placement transformation

Post by bernd »

Great! Exactly what I need :D

Where did you get it from, or did you just coded it?
User avatar
Chris_G
Veteran
Posts: 2602
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: placement transformation

Post by Chris_G »

just coded
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: placement transformation

Post by bernd »

Chris_G wrote: Fri Apr 03, 2020 3:08 pmjust coded
wow

how do I apply a relative placement to a object

obj.Placement = myRelativePlacment would set the Placement to myRelativePlacment and not apply myRelativePlacment on top of Placement AFAIK
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: placement transformation

Post by bernd »

Code: Select all

obj.Placement = myRelativePlacment.multiply(obj.Placement)
seams to do the trick
Post Reply