@lwx228问: JSL如何计算第四个点是否与前三个点在同一个圆上?题目是关于通过三点的圆的几何问题。 附上 JSL。
Graph with three movable points, A, B, C that draws a circle through the points具有三个可移动点 A、B、C 的图形,通过这些点绘制一个圆
该图显示了点 A、B 和 C 的三个方形黑色手柄。 把它们拖来拖去。 它显示两条蓝线,A 和 C。 它显示了它们的绿色中点和点缀的橙色垂直平分线。 它显示了平分线相交的橙色点。 它显示了圆心和半径穿过 A、B 和 C 的洋红色圆。
// https://www.geeksforgeeks.org/program-for-point-of-intersection-of-two-lines/
lineLineIntersection = Function( {Ax, Ay, Bx, By, Cx, Cy, Dx, Dy},
{a1, b1, c1, a2, b2, c2, determinant, x, y}, // locals
// Line AB represented as a1x + b1y = c1
a1 = By - Ay;
b1 = Ax - Bx;
c1 = a1 * (Ax) + b1 * (Ay);
// Line CD represented as a2x + b2y = c2
a2 = Dy - Cy;
b2 = Cx - Dx;
c2 = a2 * (Cx) + b2 * (Cy);
determinant = a1 * b2 - a2 * b1;
If( determinant == 0,
// The lines are parallel. This is simplified
// by returning a pair of FLT_MAX
{., .}; // return
, // else
x = (b2 * c1 - b1 * c2) / determinant;
y = (a1 * c2 - a2 * c1) / determinant;
Eval List( {x, y} );// return
);
);
New Window( "Example",
ax = 20,
ay = 50;
bx = 30;,
by = 70;
cx = 90;,
cy = 20;
Graph Box(
Frame Size( 500, 500 ),
Text( {0, 2}, "Drag the square handles" );
Handle(
ax,
ay,
ax = x;
ay = y;
);
Handle(
bx,
by,
bx = x;
by = y;
);
Handle(
cx,
cy,
cx = x;
cy = y;
);
//Circle( {0, 0}, Sqrt( exx * exx + exy * exy ) );
Text( {ax, ay}, " A" );
Text( {bx, by}, " B" );
Text( {cx, cy}, " C" );
Pen Color( "blue" );
Line( {ax, ay}, {bx, by} );// "line a"
Line( {cx, cy}, {bx, by} );// "line c"
slopeLineA = (ay - by) / (ax - bx);
slopeLineC = (cy - by) / (cx - bx);
// the slope is missing if source line is vertical
perpSlopeA = If( Is Missing( slopeLineA ),
0,
-1 / slopeLineA
);
perpSlopeC = If( Is Missing( slopeLineC ),
0,
-1 / slopeLineC
);
midpointAx = (ax + bx) / 2;
midpointAy = (ay + by) / 2;
midpointCx = (cx + bx) / 2;
midpointCy = (cy + by) / 2;
Fill Color( "green" );
Circle( {midpointAx, midpointAy}, .9, "FILL" );
Circle( {midpointCx, midpointCy}, .9, "FILL" );
// the perp slope is missing if it is vertical --
// because source line was horizontal (rise = 0)
Pen Color( "red" );
Line Style( "dotted" );
If( Is Missing( perpSlopeA ),
pax0 = midpointAx;
pay0 = midpointAy - 100;
pax1 = midpointAx;
pay1 = midpointAy + 100;
, // else ... find two far-away points and draw line
pax0 = midpointAx - 100;
pay0 = midpointAy - 100 * perpSlopeA;
pax1 = midpointAx + 100;
pay1 = midpointAy + 100 * perpSlopeA;
);
Line( {pax0, pay0}, {pax1, pay1} );
If( Is Missing( perpSlopeC ),
pcx0 = midpointCx;
pcy0 = midpointCy - 100;
pcx1 = midpointCx;
pcy1 = midpointCy + 100;
, // else
pcx0 = midpointCx - 100;
pcy0 = midpointCy - 100 * perpSlopeC;
pcx1 = midpointCx + 100;
pcy1 = midpointCy + 100 * perpSlopeC;
);
Line( {pcx0, pcy0}, {pcx1, pcy1} );
Line Style( "solid" );
pensize(2);
{xc, yc} = lineLineIntersection( pax0, pay0, pax1, pay1, pcx0, pcy0, pcx1, pcy1 );
Fill Color( "orange" );
Circle( {xc, yc}, .9, "FILL" );
Pen Color( "magenta" );
// choose distance to A, could use B or C too...
Circle( {xc, yc}, Sqrt( (xc - ax) ^ 2 + (yc - ay) ^ 2 ) );
);
);
如果您来到这里,您可能正在寻找这个 JMP 14 函数 Fit Circle。
FitCircle output from the Scripting Index.脚本索引的 FitCircle 输出。