Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to @ubutbu for pointing out the solution for me, figured I would post a working implementation in case someone googles upon this question with a need in the future:</p> <pre><code>def findParallelT(P, V): """finds the t value along a quadratic Bezier such that its tangent (1st derivative) is parallel with the direction vector V. P : a 3x2 matrix containing the control points of B(t). V : a pair of values representing the direction of interest (magnitude is ignored). returns 0.0 &lt;= t &lt;= 1.0 or None Note the result may be in the same direction or flipped 180 degrees from V""" #refer to answer given by 'unutbu' on the stackoverflow question: #http://stackoverflow.com/questions/20825173/how-to-find-a-point-if-any-on-quadratic-bezier-with-a-given-tangent-direction #for explanation. # also the 'Rearrange It' app at http://www.wolframalpha.com/widgets/view.jsp?id=4be4308d0f9d17d1da68eea39de9b2ce was invaluable. assert len(P)==3 and len(P[0])==2 and len(P[1])==2 and len(P[2])==2 assert len(V)==2 P1=P[0] P2=P[1] P3=P[2] # B(t) = P1 * (1-t)**2 + 2*P2*(1-t)*t + P3*t**2 # B'(t) = 2 * (1-t) * (P2 - P1) + 2*t*(P3-P2) # B'(t) = (a*t + b, c*t + d), V = (e, f) a = -2 * (P2[0] - P1[0]) + 2 * (P3[0]-P2[0]) b = 2 * (P2[0] - P1[0]) c = -2 * (P2[1] - P1[1]) + 2 * (P3[1]-P2[1]) d = 2 * (P2[1] - P1[1]) e = V[0] f = V[1] # -(a*t+b)*f + (c*t+d)*e = 0 for parallel... t = (d*e - b*f) / (a*f - c*e) num = float(d * e - b * f) den = float(a * f - c * e) if den == 0: return None else: t = num / den return t if 0.0 &lt;= t &lt;= 1.0 else None if __name__ == "__main__": assert findParallelT([[0.0,0.0], [0.0,25.0], [25.0,25.0]], [25.0,25.0]) == 0.5 assert findParallelT([[0.0,0.0], [0.0,25.0], [25.0,25.0]], [25.0,-25.0]) == None assert findParallelT([[200.0,200.0], [10.0, 20.0], [300.0, 0.0]], [10.0,0.0]) == None assert findParallelT([[407.5, 376.5],[321.0,463.0],[321.0,586.0]], [-246.0,0.0] ) == None assert findParallelT([[617.0, 882.0],[740.0, 882.0], [826.5, 795.5]], [-245.0,0.0]) == 0.0 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload