Notifications
Clear all
[Closed] How to Create a arc through 3 points with maxscript?
Sep 19, 2021 7:41 pm
I want create a arc with 3 points .Then I can redawn the dwg quickly. How can I realize that?
Sep 19, 2021 7:41 pm
for those particular solutions thats 3 points and 2 tangents btw or are we talking circle fitting ?
Sep 19, 2021 7:41 pm
for the latter… something like this ?
fn intersection2d p1 r1 p2 r2 =
(
dx = p2.x - p1.x, dy = p2.y - p1.y;
det = r2.x * r1.y - r2.y * r1.x;
p1 + r1 * (dy * r2.x - dx * r2.y) / det;
)
fn make_arc a b c =
(
ab = b - a;
bc = c - b;
mab = a + 0.5 * ab;
mbc = b + 0.5 * bc;
ab = normalize ab
bc = normalize bc
r1 = [-ab.y, ab.x, ab.z];
r2 = [-bc.y, bc.x, bc.z];
p = intersection2d mab r1 mbc r2;
r = distance p a;
arc radius:r pos:p from:(180 + (atan2 (p.y - c.y) (p.x - c.x))) to:(180 + (atan2 (p.y - a.y) (p.x - a.x)))
)
where a, b and c are the 3 positions in world space, we don’t check for parallel lines in the intersection by the way so if a b c are colinear there’s going to be trouble
Sep 19, 2021 7:41 pm
Very nice work! You got it working in a few lines of code. Thank you very much.
Sep 19, 2021 7:41 pm
thanks, you could add a dot ab bc == 1.0
test and if true create a line instead…
sp = splineshape();
sl = addnewSpline sp;
addKnot sp sl #bezierCorner #curve a a (a + (b - a)/3.0);
addKnot sp sl #bezierCorner #curve c (c - (c - b)/3.0) c;
updateShape sp
sp;