mathandy / svgpathtools

A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves.
MIT License
558 stars 142 forks source link

Perpendicular distance between point and segment, angle between intersecting lines #151

Closed TalalWasim closed 3 years ago

TalalWasim commented 3 years ago

Hello,

I had a question. I was wondering if it was somehow possible to calculate the perpendicular distance between a segment and an arbitrary point? The radial range function does give the "minimum/maximum" distance, between segment and point, but that minimum distance is not necessarily the perpendicular one, right? Because I have been playing around with a couple of SVGs and in some cases the tangent at the minimum distance point is not perpendicular. I might be wrong about this so please correct me if I am.

Secondly, given given two intersecting Line segments, is there an optimal way to calculate the angle between them? I need to do it for a large number (<100000) of intersecting line segments

mathandy commented 3 years ago

Regarding the first question, I don't think I know how to do this algebraically. I once posted about what is essentially this problem (I think): https://mathoverflow.net/questions/207252/explicitly-describing-the-region-of-the-plane-outward-of-a-simple-open-orien

I'd advice sampling the first segment at a number of points and intersecting the normal line at each point with the second segment, this will ll get you an estimate.

Regarding the angle between two line segments, the inverse cosine of the dot product of the two unit_tangent vectors will give you that.