Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to sketch arc given end point and radius #1705

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion cadquery/sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -875,6 +875,26 @@

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()

Check warning on line 892 in cadquery/sketch.py

View check run for this annotation

Codecov / codecov/patch

cadquery/sketch.py#L888-L892

Added lines #L888 - L892 were not covered by tests

val = Edge.makeThreePointArc(Vector(p1), Vector(p2), Vector(p3))

Check warning on line 894 in cadquery/sketch.py

View check run for this annotation

Codecov / codecov/patch

cadquery/sketch.py#L894

Added line #L894 was not covered by tests

return self.edge(val, tag, forConstruction)

Check warning on line 896 in cadquery/sketch.py

View check run for this annotation

Codecov / codecov/patch

cadquery/sketch.py#L896

Added line #L896 was not covered by tests

@arc.register
def arc(
self: T,
Expand Down