Incorrect tangent ending of spline #1870
Replies: 3 comments
-
I have another question though: how can I find the actual angle of the tangent in the middle of the generated spline; I am sure it will be calculated somewhere in the code? |
Beta Was this translation helpful? Give feedback.
-
import cadquery as cq
from math import degrees
x = 170
y = 50
pts = [(0, 0), (x / 2, y / 2), (x, y)]
tgts = [(1, 0), (1, 1)] # ~15 deg at midpoint
# tgts = [(1, 0), None, (1, 1)] # ~15 deg same as above
# tgts = [(1, 0), (1, 0)] # ~27 deg
# tgts = [(1, 0), (1, 1), (1, 0)] # 45 deg
# tgts = [(1, 0), (0, 1), (1, 0)] # 90 deg
path = cq.Workplane("XY").spline(pts, tgts)
# tangetAt(0.5) is default
tangent_mid = path.val().tangentAt()
anglex = degrees(tangent_mid.getAngle(cq.Vector(1, 0, 0)))
print(tangent_mid)
print(anglex)
res = cq.Workplane("YZ").circle(3.0).sweep(path) Here is a free function example, for a simpler spline specifying tangents at endpoints only: from cadquery.func import *
from math import degrees
# free function spline
# tgts should be of length 2 for endpoints only
x = 170
y = 50
pts = [(0, 0), (x / 2, y / 2), (x, y)]
tgts = [(1, 0), (1, 1)] # ~15 deg
# tgts = [(1, 0), (1, 0)] # ~27
path = spline(pts, tgts)
tangent_mid = path.tangentAt()
anglex = degrees(tangent_mid.getAngle(Vector(1, 0, 0)))
print(tangent_mid)
print(anglex)
res = sweep(circle(3.0).move(ry=90), path, cap=True) |
Beta Was this translation helpful? Give feedback.
-
Thanks for that quick answer! The calculated angle of 27.35 degrees corroborates with the ruler/pencil/set square result of 26.5 degrees. A (rhetorical?) side question: could I have found the answer in the documentation? Please don't take offence, I know that documentation is difficult (I maintain the MyHDL repo ...) While experimenting I found a little inconvenience: Thanks again for the answer. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to create a train switch - using the following code for a single rail (simplified to a round bar).
generates this:
If I (try to) force a 90 degrees tangent in the middle you see the effect even better:
Experimenting I stumbled on the third 'tgts' definition which produces the correct 90 degrees angle.
Can someone explain?
Oops! I found it myself: the tangent vectors in the spline function are specified as starting from (0,0) - It would be good if the CadQuery 2 Documentation mentioned that :)
Beta Was this translation helpful? Give feedback.
All reactions