/ Published in: C#

Perpendicularly project a 2D point onto a 2D line.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private Point Project(Point line1, Point line2, Point toProject) { double m = (double)(line2.Y - line1.Y) / (line2.X - line1.X); double b = (double)line1.Y - (m * line1.X); double x = (m * toProject.Y + toProject.X - m * b) / (m * m + 1); double y = (m * m * toProject.Y + m * toProject.X + b) / (m * m + 1); }
URL: http://www.vcskicks.com/code-snippet/point-projection.php
Comments
