Add tangents_to_point for QuadBez - #417
Conversation
| let a = self.p0.to_vec2() - 2.0 * self.p1.to_vec2() + self.p2.to_vec2(); | ||
| let b = 2.0 * (self.p1.to_vec2() - self.p0.to_vec2()); | ||
| let c = self.p0.to_vec2() - p.to_vec2(); | ||
|
|
||
| // coefficients of x(t) \cross x'(t) | ||
| let c2 = a.cross(b); | ||
| let c1 = -2.0 * c.cross(a); | ||
| let c0 = b.cross(c); |
There was a problem hiding this comment.
I'd like a double check on the math here, both in terms of its correctness (I'm not certain of it) and its formatting (is it more faithful to the canonical Bézier equations to reverse the orders of the terms, swap the order of the cross product and negate it, etc.?). This mostly arose from pattern recognition based fiddling and I wasn't able to quite grasp its relationship with the Bézier equations on Wikipedia. So please confirm this is right.
There was a problem hiding this comment.
I think this would be a little clearer:
// Coefficients of (c + b t + a t^2) x (b + 2 a t) = 0.
let c2 = b.cross(a);
let c1 = 2.0 * c.cross(a);
let c0 = c.cross(b);
There was a problem hiding this comment.
I'd drop the "= 0" in the comment, but otherwise I agree that it's easier to follow this way.
I'd also maybe add a comment like this near the top:
// Reparameterize `self - p` as `a t^2 + b t + c`
|
should grow some tests, these are from Codex and would be cleaner if another PR (#556) of mine lands (since they wouldn't have to call |
waywardmonkeys
left a comment
There was a problem hiding this comment.
Needs tests and a rebase forward.
| let a = self.p0.to_vec2() - 2.0 * self.p1.to_vec2() + self.p2.to_vec2(); | ||
| let b = 2.0 * (self.p1.to_vec2() - self.p0.to_vec2()); | ||
| let c = self.p0.to_vec2() - p.to_vec2(); | ||
|
|
||
| // coefficients of x(t) \cross x'(t) | ||
| let c2 = a.cross(b); | ||
| let c1 = -2.0 * c.cross(a); | ||
| let c0 = b.cross(c); |
There was a problem hiding this comment.
I think this would be a little clearer:
// Coefficients of (c + b t + a t^2) x (b + 2 a t) = 0.
let c2 = b.cross(a);
let c1 = 2.0 * c.cross(a);
let c0 = c.cross(b);
Follows up #288 which added
tangents_to_point()toCubicBez, by adding it toQuadBeznow as well.