From 68e08fac715903e3e7ce7d43834b3967c247b01a Mon Sep 17 00:00:00 2001 From: spike Date: Sun, 17 Nov 2024 15:37:05 +0100 Subject: [PATCH] Add function to sketch arc given end point and radius --- cadquery/sketch.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cadquery/sketch.py b/cadquery/sketch.py index f76c90dc3..ab86183e4 100644 --- a/cadquery/sketch.py +++ b/cadquery/sketch.py @@ -15,7 +15,7 @@ overload, ) -from math import tan, sin, cos, pi, radians, remainder +from math import tan, sin, cos, pi, radians, remainder, sqrt from itertools import product, chain from multimethod import multimethod from typish import instance_of, get_type @@ -875,6 +875,26 @@ def arc( return self.edge(val, tag, forConstruction) + @arc.register + def arc( + self: T, + p3: Point, + r: Real, + ccw: bool = False, + tag: Optional[str] = None, + forConstruction: bool = False, + ) -> T: + + p1 = self._endPoint() + z = Vector(0, 0, -1) if ccw else Vector(0, 0, 1) + cord = -Vector(p1) + Vector(p3) + sagitta = r - sqrt(r ** 2 - (cord.Length / 2) ** 2) + p2 = (Vector(p1) + Vector(p3)) / 2 + sagitta * cord.cross(z).normalized() + + val = Edge.makeThreePointArc(Vector(p1), Vector(p2), Vector(p3)) + + return self.edge(val, tag, forConstruction) + @arc.register def arc( self: T,