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!
edwilliams16
Veteran
Posts: 3191
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Post by edwilliams16 »

Two circles worked - but two spheres created a tessellated body - like it used the regular importer despite the message.

Code: Select all

07:36:21  Processing : /Users/ed/Downloads/Two-Circles-Hull.csg
07:36:21  Using Alternate OpenSCAD Importer
07:36:21  Circle Shape : True
07:36:21  Circle Shape : True
07:36:21  End processing CSG file
07:37:01  Processing : /Users/ed/Downloads/Two-Spheres-Hull.csg
07:37:01  Using Alternate OpenSCAD Importer
07:37:01  End processing CSG file
So now you are working on two parallel cylinders? The skew case will certainly be more complicated...
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 »

edwilliams16 wrote: Sun Apr 11, 2021 5:42 pm Two circles worked - but two spheres created a tessellated body - like it used the regular importer despite the message.
If you use File | Open and then select the file you should get a prompt like
A2DD9B28-4865-468D-90B3-A024403FB57A_4_5005_c.jpeg
A2DD9B28-4865-468D-90B3-A024403FB57A_4_5005_c.jpeg (29.82 KiB) Viewed 879 times
The other reason it might not have worked is that you had not checked out branch newmayer.
Ypu need to go to .../Mod/OpenSCAD_Alt_Imporrt and run the command git checkout newmayer.
edwilliams16
Veteran
Posts: 3191
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Post by edwilliams16 »

Got your test file working (needed the git checkout), however if I translate a sphere in the z-direction, it fails.

Try:

Code: Select all

hull() {
	sphere($fn = 0, $fa = 12, $fs = 2, r = 5);
	multmatrix([[1, 0, 0, 20], [0, 1, 0, 0], [0, 0, 1, 20], [0, 0, 0, 1]]) {
		sphere($fn = 0, $fa = 12, $fs = 2, r = 10);
	}
}
as the csg
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 »

edwilliams16 wrote: Sun Apr 11, 2021 7:52 pm Got your test file working (needed the git checkout), however if I translate a sphere in the z-direction, it fails.

Try:

Code: Select all

hull() {
	sphere($fn = 0, $fa = 12, $fs = 2, r = 5);
	multmatrix([[1, 0, 0, 20], [0, 1, 0, 0], [0, 0, 1, 20], [0, 0, 0, 1]]) {
		sphere($fn = 0, $fa = 12, $fs = 2, r = 10);
	}
}
as the csg
Same bug if two circles :-(
edwilliams16
Veteran
Posts: 3191
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Post by edwilliams16 »

keithsloan52 wrote: Sun Apr 11, 2021 8:34 pm
Same bug if two circles :-(
In OpenSCAD hull() doesn't work in 3D on 2D objects, It projects the objects onto the xy-plane, so I didn't expect it to work on circles that were not co-planar. https://en.wikibooks.org/wiki/OpenSCAD_ ... tions#hull

On the other hand, it should be expected to work for two spheres regardless of their placement. Looking at your code (I can't debug it readily, see https://forum.freecadweb.org/viewtopic.php?f=4&t=57657), it appears you haven't ensured that all your four circles are in the same plane. They need to be all in some plane containing the line between their centers. Note that their Placement.Rotation.Axis are irrelevant. You can rotate a sphere around any axis and it remains unchanged. You need to define Part.Circle.Axis in a common direction orthogonal to v1 - v2. One way is to cross-product v1 - v2 with the three axis directions and choose one that is non-zero. You need to special case v1=v2 anyway - return the larger sphere.

The other thing that looks like an error to me is the definition of l2, surely it should be
  • l2 = Part.makeLine(c2.value(t3), c1.value(t3 + Math.pi))
or it won't connect up with a2?
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 »

edwilliams16 wrote: Sun Apr 11, 2021 9:35 pm In OpenSCAD hull() doesn't work in 3D on 2D objects, It projects the objects onto the xy-plane, so I didn't expect it to work on circles that were not co-planar. https://en.wikibooks.org/wiki/OpenSCAD_ ... tions#hull
So I see
08807832-2B2F-4351-B352-D498DBB5BE6F.jpeg
08807832-2B2F-4351-B352-D498DBB5BE6F.jpeg (77.18 KiB) Viewed 813 times
Where as currently in FreeCAD
5116A1E4-271E-40C3-82CC-A8446F2106CD.jpeg
5116A1E4-271E-40C3-82CC-A8446F2106CD.jpeg (154.22 KiB) Viewed 813 times
Two spheres was based on treating as two circles then revolved so resolving situation with 2D might fix two spheres .
edwilliams16
Veteran
Posts: 3191
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Post by edwilliams16 »

The 2D case will require even more coding because a tilted circle projects down to an ellipse. In general, you'll have to construct the common tangent of two ellipses, which is more complicated than the two circle case. The 3D case of two spheres only requires the fixes I already gave.

Here's a generic 2D case:

Code: Select all

hull() {
      rotate(35, [1, 0 ,1]) circle($fn = 0, $fa = 12, $fs = 2, r = 25 );
      translate([40,0,40]) rotate(60, [1,1,1]) circle($fn = 0, $fa = 12, $fs = 2, r = 5);
Screen Shot 2021-04-11 at 10.58.09 PM.png
Screen Shot 2021-04-11 at 10.58.09 PM.png (16.71 KiB) Viewed 797 times
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 »

edwilliams16 wrote: Mon Apr 12, 2021 8:59 am The 2D case will require even more coding because a tilted circle projects down to an ellipse. In general, you'll have to construct the common tangent of two ellipses, which is more complicated than the two circle case. The 3D case of two spheres only requires the fixes I already gave.

Here's a generic 2D case:

Code: Select all

hull() {
      rotate(35, [1, 0 ,1]) circle($fn = 0, $fa = 12, $fs = 2, r = 25 );
      translate([40,0,40]) rotate(60, [1,1,1]) circle($fn = 0, $fa = 12, $fs = 2, r = 5);
Screen Shot 2021-04-11 at 10.58.09 PM.png
Think it is going to be a case of check if they are planer and then fine, if not resort to OpenSCAD and Mesh/DXF
edwilliams16
Veteran
Posts: 3191
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

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

Post by edwilliams16 »

I'm not sure what the use case is for the 2D version.
Anyhow, I fixed OpenSCADHull.py as I described above so it works for other placements of two spheres. It would take a while to figure out enough git to create a pull request, so here's the fixed file:
Attachments
OpenSCADHull.py
(13.59 KiB) Downloaded 17 times
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 »

edwilliams16 wrote: Mon Apr 12, 2021 9:31 pm I'm not sure what the use case is for the 2D version.
Anyhow, I fixed OpenSCADHull.py as I described above so it works for other placements of two spheres. It would take a while to figure out enough git to create a pull request, so here's the fixed file:
Thanks I added and merged.

Okay assume I have two cylinders, or might be a cylinder and a cone, arbitrary position and rotation other than collinear ( Not sure if that is correct term) but axis of cylinder/cone are the same.

Is there a good way to check if they are collinear from their Position.Rotations which would have to be equal and Position.Bases bases such that a vector from the Base of one to the other would also be collinear with the axis.
Post Reply