# [OpenSCAD] Maths problem = finding corners of an intersection of 2 polygons

Michael Marx michael.marx at tpg.com.au
Sat Jul 20 22:27:18 EDT 2019

```> But I'm still interested in solving with maths,

Plus https://rosettacode.org/wiki/Find_the_intersection_of_two_lines should be hints enough?

p1=[[378.546,352.217],[458.698,272.065],[384.642,252.783],[324.204,313.221]];

p2=[[379.141,252.143],[470.219,343.221],[403.88,370.221],[301.294,267.635]];

intersection()

{

%polygon(p1);

#polygon(p2);

}

plot(p1,size=1.5);

plot(p2,size=2,c="green");

line(p1[0], p1[1]);

line(p2[0], p2[1], c="green");

module line(a,b,thick=1,c="blue") {

color(c)

hull() {

translate(a) circle(thick);

translate(b) circle(thick);

}

}

module plot(v,size=1,c="blue") { // v=[ [x,y,z] or [x,y], ... ]

d3=(len(v[0])==3);

for(j=[0:len(v)-1]) {

i=v[j];

translate([i.x,i.y,d3 ? i.z : 0]) { //echo(i,j);

color(c)

if (d3)

sphere(size,\$fn=12);

else

circle(size,\$fn=8);

%color("black")

translate([0,-1,0.1])

if (d3)

linear_extrude(height=1)

text(str(j),size=size*4);

else

text(str(j),size=size*4);

}

}

}

_____

From: Discuss [mailto:discuss-bounces at lists.openscad.org] On Behalf Of Alex Gibson
Sent: Sun, 21 Jul 2019 11:12
Subject: Re: [OpenSCAD] Maths problem = finding corners of an intersection of 2 polygons

.so that's my problem solved for this time.

But I'm still interested in solving with maths, with the idea of making a post-processing tool...

Alex Gibson

edumaker limited

*         Project management

*         Operations & Process improvement

*         3D Printing

From: Discuss [mailto:discuss-bounces at lists.openscad.org] On Behalf Of Alex Gibson
Sent: 21 July 2019 02:05
Subject: Re: [OpenSCAD] Maths problem = finding corners of an intersection of 2 polygons

Yep - playing the GCODE back in Simplify3D gets a perfect square:

That is:

G92 E0

G1 X378.546 Y352.217

G1 X458.698 Y272.065 E76.6848 ;

G1 X457.434 Y271.615

G1 X384.642 Y252.783

G1 X324.204 Y313.221 E144.1098 ;

G1 X323.103 Y312.381

G1 X379.141 Y252.143

G1 X470.219 Y343.221 E58.8828 ;

G1 X469.321 Y343.146

G1 X403.880 Y370.221

G1 X301.294 Y267.635 E129.3704 ;

; layer 717, Z = 359.250

G1 Z359.250

G1 X382.211 Y348.552

G1 X428.88 Y301.883 E76.6848 ;

G1 X382.211 Y255.214 E144.1098 ;

G1 X335.542 Y301.883 E58.8828 ;

G1 X382.211 Y348.552 E129.3704 ;

Now I just have to make a couple of versions of this, one repeating 3 times with no extrusion and
one just once with extrusion, and jog the printer in between until I find the perfect offset!

Thanks again

Alex Gibson

edumaker limited

*         Project management

*         Operations & Process improvement

*         3D Printing

From: Discuss [mailto:discuss-bounces at lists.openscad.org] On Behalf Of Alex Gibson
Sent: 21 July 2019 01:49
Subject: Re: [OpenSCAD] Maths problem = finding corners of an intersection of 2 polygons

Fantastic, thanks Torsten, I was just thinking on similar lines...

I remembered an online STL to OpenSCAD converter.

So I did a Linear_extrude of my intersection and got:

Then used this dead useful tool https://jsfiddle.net/Riham/yzvGD/ to get:

module object1(scale) {polyhedron(

points=[[382.211,348.552,0],[428.88,301.883,0],[382.211,255.214,0],[382.211,348.552,0],[382.211,255
.214,0],[335.542,301.883,0],[382.211,255.214,10],[428.88,301.883,10],[382.211,348.552,10],[335.542,
301.883,10],[382.211,255.214,10],[382.211,348.552,10],[382.211,348.552,0],[428.88,301.883,10],[428.
88,301.883,0],[382.211,348.552,0],[382.211,348.552,10],[428.88,301.883,10],[335.542,301.883,0],[382
.211,348.552,10],[382.211,348.552,0],[335.542,301.883,0],[335.542,301.883,10],[382.211,348.552,10],
[382.211,255.214,0],[335.542,301.883,10],[335.542,301.883,0],[382.211,255.214,0],[382.211,255.214,1
0],[335.542,301.883,10],[428.88,301.883,0],[382.211,255.214,10],[382.211,255.214,0],[428.88,301.883
,0],[428.88,301.883,10],[382.211,255.214,10] ],

faces=[[0,1,2],[3,4,5],[6,7,8],[9,10,11],[12,13,14],[15,16,17],[18,19,20],[21,22,23],[24,25,26],[27
,28,29],[30,31,32],[33,34,35]]);}

translate([200,0,0])

object1(1);

Which if I strip it down a bit gets:

module object4(scale) {polyhedron(

points=[[382.211,348.552,0],

[428.88,301.883,0],

[382.211,255.214,0],

[335.542,301.883,0]],

faces=[[0,1,2,3]]);}

object4(1);

.which are exactly the same co-ordinates you got with rounding error of 0.001mm so that's verified
nicely via 2 methods!

Thanks very much!!!

Now I can use these co-ordinates to make a GCODE file that plays repeats of a square movement
between those co-ordinates, and finally one that extrudes plastic for when I think I've jogged X
and Y successfully!

Alex Gibson

edumaker limited

. Project management

. Operations & Process improvement

. 3D Printing

-----Original Message-----
From: Discuss [mailto:discuss-bounces at lists.openscad.org] On Behalf Of Torsten Paul
Sent: 21 July 2019 01:39
Subject: Re: [OpenSCAD] Maths problem = finding corners of an intersection of 2 polygons

On 21.07.19 02:20, Alex Gibson wrote:

> 2)      A way to get OpenSCAD to output the corner co-ordinates?

Export as SVG, that gives:

M 428.88,-301.882 L 382.211,-348.552 L 335.542,-301.883 L 382.212,-255.214 z

Note that the Y coordinates are negated due to SVG coordinate

system having the origin top left.

ciao,

Torsten.

_______________________________________________

---
This email has been checked for viruses by AVG.
https://www.avg.com
-------------- next part --------------
An HTML attachment was scrubbed...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.jpg
Type: image/jpeg
Size: 3958 bytes
Desc: not available
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.jpg
Type: image/jpeg
Size: 3249 bytes
Desc: not available
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 27792 bytes
Desc: not available