you want a line which contains the mentioned 3 points?
On Sun, 17 Apr 2022 at 00:48, Jan Öhman via Discuss <
discuss@lists.openscad.org> wrote:
---------- Forwarded message ----------
From: "Jan Öhman" jan_ohman@yahoo.com
To: OpenSCAD general discussion discuss@lists.openscad.org
Cc:
Bcc:
Date: Sat, 16 Apr 2022 19:21:25 +0000 (UTC)
Subject: [OpenSCAD] Re: Calculate points in an arc
Thanks!
Tried to analyze the answer (but, do not see how it will solve my desire)
I have 3 points that I want "a line" through to create the 2D object.
Points
x1=10, y1=49.25
x2=55,5, y2=50,5
x3=101, y3=49,5
(right now I do not see the solution)
Den fredag 8 april 2022 18:47:59 CEST, Ronaldo Persiano <
rcmpersiano@gmail.com> skrev:
To find an arc given 3 2D points you may find the intersection point of
two lines respectively bisecting the first pair and the last pair of
points. However, the reference I have given before makes possible a more
concise computation. Here is my version:
// based on
//
https://en.wikipedia.org/wiki/Circumscribed_circle#Cartesian_coordinates
// return a list of fn points in the circular arc starting at p0,
// passing by p1 and ending at p2
function 3points_arc(p0, p1, p2, fn=10) =
// an alternative expression for D
// D = 2 * ( (p1-p0).x * (p2-p0).y - (p1-p0).y * (p2-p0).x )
let( D = 2 * cross(p1-p0, (p2-p0)) )
assert( abs(D)>1e-9, "The 3 points should not be collinear." )
let(
Ux = ( (p2-p0).y*(p1-p0)(p1-p0) - (p1-p0).y(p2-p0)(p2-p0)
)/D,
Uy = ( (p1-p0).x(p2-p0)(p2-p0) - (p2-p0).x(p1-p0)(p1-p0)
)/D,
radius = norm([Ux,Uy]),
center = [Ux,Uy] + p0,
ang0 = atan2( (p0-center).y, (p0-center).x ),
ang2 = atan2( (p2-center).y, (p2-center).x ),
// the points are in a cw winding iff D<0
// the angular difference between vectors p2-center and p0-center
// measured from p0-center; dang is positive iff D is negative
dang = D<0 ? ang2<ang0 ? ang2-ang0 : ang2-ang0-360
: ang2>ang0 ? ang2-ang0 : ang2-ang0+360
)
[ for(i=[0:fn-1])
let( ang = ang0 + idang/(fn-1) )
center + radius*[cos(ang),sin(ang)] ] ;
// Application example
// randomly generate 3 points
seed = floor(rands(0,10000,1)[0]);
echo(seed=seed); // seed allows for case recall
rnds = rands(0,20,6, seed=seed);
pts = [for(i=[0:2:5]) [rnds[i], rnds[i+1]] ];
//pts = [ [10, 49.25], [60.5, 51.5], [101, 49.25] ];
// draw a polyline connecting the arc points
line(3points_arc(pts[0], pts[1], pts[2], 23), width=.2);
// connect the 3 point path with blue lines
color("blue") line(pts, width=.2);
// mark the start point with a red "dot"
color("red") translate(pts[0]) circle(.35);
// a helper module to trace a 2D or 3D polyline
module line(path, width=1) {
for(i=[0:len(path)-2]) {
hull() {
translate(path[i]) sphere(width/2);
translate(path[i+1]) sphere(width/2);
}
}
}
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
---------- Forwarded message ----------
From: "Jan Öhman via Discuss" discuss@lists.openscad.org
To: OpenSCAD general discussion discuss@lists.openscad.org
Cc: "Jan Öhman" jan_ohman@yahoo.com
Bcc:
Date: Sat, 16 Apr 2022 19:21:25 +0000 (UTC)
Subject: [OpenSCAD] Re: Calculate points in an arc
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org