Platinum Partner

Closest Line Point //JavaScript Function


Given a dot and a line, it returns the nearest dot over the line.

[UPDATED CODE AND HELP CAN BE FOUND HERE]




//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/math/closest-line-point [v1.0]

closestLinePoint = function( px, py, x, y, angle ){
	var tg = ( ( angle %= 360 ) < 0 && ( angle += 180 ), Math.tan( -angle * Math.PI / 180 ) );
	return angle < 45 || angle > 135 ? { x: px, y: ( px - x ) * tg + y } : { x: ( py - y ) / tg + x, y: py };
};


{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}