-
Notifications
You must be signed in to change notification settings - Fork 56
Conversation
✅ Build cadquery 1.0.21 completed (commit f6c83eb355 by @gntech) |
Codecov Report
@@ Coverage Diff @@
## master #254 +/- ##
==========================================
- Coverage 92.85% 92.74% -0.11%
==========================================
Files 10 10
Lines 2196 2206 +10
==========================================
+ Hits 2039 2046 +7
- Misses 157 160 +3
Continue to review full report at Codecov.
|
@gntech thanks for another contribution! this looks great! |
Actually, I was thinking about some things.
if endPoint.sub(startPoint).Length > 2 * radius:
raise ValueError
|
I think that rasing a ValueError is how we do it elsewhere. See here for a case that's inside the CQ core code, and here for a case that's in an example.
Not sure if this will do exactly what you're looking for, but you can check the length of edges. The last line in this sample code is the important one. import cadquery as cq
(L, H, W, t) = (100.0, 20.0, 20.0, 1.0)
# Define the points that the polyline will be drawn to/thru
pts = [
(W/2.0, H/2.0),
(W/2.0, (H/2.0 - t)),
(t/2.0, (H/2.0-t)),
(t/2.0, (t - H/2.0)),
(W/2.0, (t - H/2.0)),
(W/2.0, H/-2.0),
(0, H/-2.0)
]
result = cq.Workplane("front").moveTo(0, H/2.0) \
.polyline(pts)
# Do check on edge lengths here. May have to get the radius indirectly
print(result.edges('>Y').first().val().Length()) Notice the |
I would create a series of arcs and assert:
This apply_spline() function iterates along an arc or a spline getting vertices at different lengths along the wire. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion for ValueError
implementation
cadquery/cq.py
Outdated
|
||
# Calculate the sagitta from the radius | ||
length = endPoint.sub(startPoint).Length / 2.0 | ||
sag = abs(radius) - math.sqrt(radius**2 - length**2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you mentioned, if the radius < length
then the arc is not possible.
I think the best way to capture this is with a try
block over the sag
calculation
try:
sag = abs(radius) - math.sqrt(radius**2 - length**2)
except ValueError:
raise ValueError("Arc radius is not large enough to reach the given end-point")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmwright and @fragmuffin: Thanks! Good suggestions, I will try to get this implemented later this weekend.
Since both radiusArc and sagittaArc boils down to a threePointArc in the end I want to be able to just return a threePointArc. This increases code reuse. However, the function toWorldCoords seems to do something strange to a vector that already is in World coordinates. This commit checks if the point already is an Vector before trying to make it an vector. I also refined the testcases by checking edge length and edge type.
See my latest commit, I discovered something strange with the toWorldCoords function. When runned in sequence it changes the coordinates. I dont think that this is the intent? |
✅ Build cadquery 1.0.22 completed (commit 3778358d0e by @gntech) |
I realize that I made some wrong assumptions about what toWorldCoords do. But this is my intention: sagittaArc, radiusArc and threePointArc all uses startPoint and endPoint but determines the arc between them in different ways: sag, radius or midPoint. My idea is that sagittaArc and radiusArc should just calculate the corresponding midPoint and then hand that midpoint over to threePointArc for the actual arc creation. Does this sound reasonable or is it prefferred to have separate functions that create the arcs by themself? I will try to write some code later tonight to better explain. |
I don't know what @dcowden thinks, but I think your approach is fine. I try to reuse existing building blocks whenever possible, which it sounds like you're doing. |
@gntech i like your approach. |
…sion to global coords only in threePointArc
✅ Build cadquery 1.0.23 completed (commit e6768412b8 by @gntech) |
Yes, I consider this ready for merge |
+1 from me |
@gntech thanks for this contribution! You rock! |
Thank you! And thanks for your work on cadquery which is awesome! |
@gntech absolutely! thanks for the kind words. I think we can do really amazing things with cq once we get an OCC layer implemented, and we get proper feature trees and such. |
Add an function that draws an arc that is determined by startPoint, endPoint and radius.