Checking if two Placements are parallel and creating one orthogonal.

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Checking if two Placements are parallel and creating one orthogonal.

Post by keithsloan52 »

Checking if two Placements are parallel and creating one orthogonal.

Okay I have two Placements, their Rotation components have a variable Q and a Matrix.
Now unless my understanding is wrong they could have different values of Q and or Matrix and still be parallel.
How can I test if two Placements are parallel?

Also I know there is an infinite set of axis and angles for an orthogonal plane, but what is the best way to create a Placement
which is orthogonal, I am happy with any orthogonal plane as long as it is orthogonal.

Thanks
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Checking if two Placements are parallel and creating one orthogonal.

Post by onekk »

Placement is composed of two component:

The translation vector and the rotation component.

It determine at least a rotation axis, but it tells nothing about the underlying geometry (shape).

So the only thing you could confront between two placements is to retrieve the rotation axis and confront them if this have some sense.

I think that there could be a way to assume translation vector as the center and rotation as direction you could obtain two normalized vectors and confront them.

Maybe using some methods associated with vector or maybe some methods in DraftVecUtils.

But my 3d math is not so high to give you a solution.

Or maybe my assumptions are totally wrong.

I know that @OpenBrain has some depth knowledge about rotation things (no jokes) and maybe also @chrisb
Your maybe could to ping them.

Edit:

maybe using.

Code: Select all

a= FreeCAD.Placement(Vector(0,0,0), Rotation(0,45,0
ax = a.Rotation.Axis

aa = a.Rotation.Angle
If ax an as are the same they have the Sama rotation (the Angle is given in Radians)

If the Vector is different they are parallel if it is the same they overlap.

some though check with real data and see if it work.

Hope it helps.

Carlo D.
Last edited by onekk on Sat Apr 03, 2021 9:36 am, edited 1 time in total.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Checking if two Placements are parallel and creating one orthogonal.

Post by keithsloan52 »

keithsloan52 wrote: Fri Apr 02, 2021 3:56 pm Checking if two Placements are parallel and creating one orthogonal.

Okay I have two Placements, their Rotation components have a variable Q and a Matrix.
Now unless my understanding is wrong they could have different values of Q and or Matrix and still be parallel.
How can I test if two Placements are parallel?

Also I know there is an infinite set of axis and angles for an orthogonal plane, but what is the best way to create a Placement
which is orthogonal, I am happy with any orthogonal plane as long as it is orthogonal.

Thanks
Would checking if the determinant of the two rotation matrix were equal, work to check if they were parallel?

Would a Placement with a rotation Matrix set to the inverse of the first object, make it orthogonal to the first object?
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Checking if two Placements are parallel and creating one orthogonal.

Post by keithsloan52 »

keithsloan52 wrote: Sat Apr 03, 2021 9:31 am
Would checking if the determinant of the two rotation matrix were equal, work to check if they were parallel?
Well I guess not. But to normalise the matrix one would divide all elements by the determinant
and check if they all match.

Would be a lot of processing to

a) Calculate the determinant for two matrix
b) Divide each element by the determinant for two matrix
c) Check if each new element was equal

Feel there must be an easier and better way.
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Checking if two Placements are parallel and creating one orthogonal.

Post by onekk »

Maybe this could help?

http://www.euclideanspace.com/maths/alg ... /index.htm

It use quaternions, math is a little over my skills, but there are some parallel check in the formulas.

Hope it helps.

There are also some similar question on stackoverflow.

It involve cross and dot products so it seem less demanding than using matrices.

Hope it helps, I'm on mobile so not fully operative.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Checking if two Placements are parallel and creating one orthogonal.

Post by onekk »

See in FreeCAD sources draftgeoutils/geometry.py around line 413 there is a formula to check if planes are parallel, maybe it useful?

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Checking if two Placements are parallel and creating one orthogonal.

Post by keithsloan52 »

onekk wrote: Sat Apr 03, 2021 10:38 am See in FreeCAD sources draftgeoutils/geometry.py around line 413 there is a formula to check if planes are parallel, maybe it useful?

Regards

Carlo D.
Thanks but that assumes one is dealing with Faces.

I am trying to deal with a couple of cylinders with Placements.
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Checking if two Placements are parallel and creating one orthogonal.

Post by onekk »

Yes but it checks two vector, so if you do the same check using the cylinder axis as vector.

I don't know exactly the math, but it seem that the calculation is done using the length that suppose some normalisation.

Same thing, same result if the vector is from a plane, the two planes are parallel.

If the vector is the cylinder axis, the two cylinder are also parallel.

In path slots operation there are many places in which two edges are checked to be parallel or not. Maybe an eye even in this code?

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
keithsloan52
Veteran
Posts: 2764
Joined: Mon Feb 27, 2012 5:31 pm

Re: Checking if two Placements are parallel and creating one orthogonal.

Post by keithsloan52 »

onekk wrote: Sat Apr 03, 2021 12:50 pm Yes but it checks two vector, so if you do the same check using the cylinder axis as vector.

I don't know exactly the math, but it seem that the calculation is done using the length that suppose some normalisation.

Same thing, same result if the vector is from a plane, the two planes are parallel.

If the vector is the cylinder axis, the two cylinder are also parallel.

In path slots operation there are many places in which two edges are checked to be parallel or not. Maybe an eye even in this code?

Regards

Carlo D.
But cylinder ones Placement has an Axis and an Angle, Cylinder two also has an Axis and an Angle. I can see that you could check if the two axis are parallel, but if the angles are different the Placements are not parallel. Similarly the Placements could be parallel, but the axis not.
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Checking if two Placements are parallel and creating one orthogonal.

Post by onekk »

But solids are constructed in same manner cylinder is done with center of the base in (0,0,0) and then rotated to position.

so if the solid is the same, axis and angle are the same if they are parallel, try some sample test and.

Axis and Angle is only one of the possible data returned, you could use Q (quaternion) and Matrix.

as the rotation component is separate from translation the rotation will be the same (only the translation vector, will be different).

Using Matrix and axis and angle I suppose that maybe there will be problem with different combination of value for the same rotation, from the little I know Quaternion are not affected from this problem.
Have you tried with some test shapes?

From the sources of FreeCAD I see some test that verify that rotation is checked for isEqual even if it is Angle is added by 360 or even 180 so maybe some checks and normalisations are done in the code.

But take this post as a mere discussion (eater egg hunts 😄) .

I hope that someone with a more mathematical background will be answering this post, but I suppose that this will happen maybe after present holidays.

Now I'm not at my computer so I could not test code on FreeCAD.

I didn't remember if I have told you that in draftgeoutils edge.py there is a getRotation method, (it is calculated for an edge but I think that is not difficult to obtain the centers of top and bottom face of cylinder do obtain a line with Part.LineSegment().

Sorry if this discussion has bothered you.

For now Good Easter and Regards.
Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply