From: Diederik v. L. <ma...@di...> - 2011-08-30 19:01:01
|
Hi all, Due to popular demand, I'm thinking of implementing tangential and perpendicular snapping in Inkscape. Well, at least for the case where the user draws a straight line or manipulates a guide. So I have a curve I want to snap to, and some distant point P0. Now I need to find all points P1, for which the line P0-P1 is either tangential or perpendicular to the curve. I guess I could first convert the path to sbasis, and then call find_tangents() (see the code snippet below, from sbasis-geometric.cpp). But a few questions come to mind: - Can't this be done without having to convert each path to sbasis first? Converting will take CPU time - Am I really the first one to need this functionality? find_tangets() is not being used anywhere as far as I can tell. Are there other ways to solve this? - How do I implement perpendicular snapping? There's no method yet called find_normals() It would me much appreciated if someone could shed some light on this. Diederik /** * \brief returns all the parameter values of A whose tangent passes through P. * \relates D2 */ std::vector<double> find_tangents(Point P, D2<SBasis> const &A) { SBasis crs (cross(A - P, derivative(A))); crs = shift(crs*Linear(-1, 0)*Linear(-1, 0), -2); // We know that there is a double root at t=0 so we divide out t^2 // JFB points out that this is equivalent to (t-1)^2 followed by a divide by s^2 (shift) return roots(crs); } |