http://nickpisca.com/BLAST/index.php?title=CSharp_Get2DClosestPointToLineSegment&feed=atom&action=history
CSharp Get2DClosestPointToLineSegment - Revision history
2024-03-28T08:48:42Z
Revision history for this page on the wiki
MediaWiki 1.28.1
http://nickpisca.com/BLAST/index.php?title=CSharp_Get2DClosestPointToLineSegment&diff=38&oldid=prev
Nickpisca: Created page with " static double[] Get2DClosestPointToLineSegment(double[] A, double[] B, double[] OffPt, bool SkipExtremities) { double mAB = (B[1] - A[1]) / (B[0..."
2017-04-22T05:06:32Z
<p>Created page with " static double[] Get2DClosestPointToLineSegment(double[] A, double[] B, double[] OffPt, bool SkipExtremities) { double mAB = (B[1] - A[1]) / (B[0..."</p>
<p><b>New page</b></p><div> static double[] Get2DClosestPointToLineSegment(double[] A, double[] B, double[] OffPt, bool SkipExtremities)<br />
{<br />
double mAB = (B[1] - A[1]) / (B[0] - A[0]);<br />
double mCD = -1 * (B[0] - A[0]) / (B[1] - A[1]);<br />
<br />
double bAB = B[1] - (mAB * B[0]);<br />
double bCD = OffPt[1] - (mCD * OffPt[0]); <br />
<br />
double fx = (bCD - bAB) / (mAB - mCD);<br />
double fy = (mAB * fx) + bAB;<br />
<br />
double[] D = {fx, fy, 0.0};<br />
double[] diff = [[CSharp_ArraySubtraction|ArraySubtraction]](D, OffPt); <br />
double DistMag = [[CSharp_ArrayVectorMag|ArrayVectorMag]](diff);<br />
<br />
double[] diffAB = [[CSharp_ArraySubtraction|ArraySubtraction]](A, B);<br />
double[] diffAD = [[CSharp_ArraySubtraction|ArraySubtraction]](D, A);<br />
double[] diffBD = [[CSharp_ArraySubtraction|ArraySubtraction]](D, B);<br />
double magAB = [[CSharp_ArrayVectorMag|ArrayVectorMag]](diffAB);<br />
double magAD = [[CSharp_ArrayVectorMag|ArrayVectorMag]](diffAD);<br />
double magBD = [[CSharp_ArrayVectorMag|ArrayVectorMag]](diffBD);<br />
<br />
double[] winA = {0.0,0.0,0.0,0.0};<br />
if (magAB < (magAD + magBD - 0.00001))<br />
{<br />
if (SkipExtremities == true)<br />
{<br />
winA[0] = 10000000.0; winA[1] = 10000000.0; winA[2] = 0.0; winA[3] = 10000000.0;<br />
}<br />
else<br />
{<br />
if (magAD < magBD)<br />
{<br />
double[] diffAC = [[CSharp_ArraySubtraction|ArraySubtraction]](A, OffPt);<br />
double magAC = [[CSharp_ArrayVectorMag|ArrayVectorMag]](diffAC);<br />
winA[0] = A[0]; winA[1] = A[1]; winA[2] = 0.0; winA[3] = magAC;<br />
}<br />
else<br />
{<br />
double[] diffBC = [[CSharp_ArraySubtraction|ArraySubtraction]](B, OffPt);<br />
double magBC = [[CSharp_ArrayVectorMag|ArrayVectorMag]](diffBC);<br />
winA[0] = B[0]; winA[1] = B[1]; winA[2] = 0.0; winA[3] = magBC;<br />
}<br />
}<br />
}<br />
else<br />
{<br />
winA[0] = fx; winA[1] = fy; winA[2] = 0.0; winA[3] = DistMag;<br />
}<br />
<br />
return winA;<br />
}<br />
<br />
<br />
<br />
''This subroutine was used in the development of the [http://0001design.com/?page_id=199 Mega-Dots World's Toughest Connect-the-Dots Puzzles].<br />
<br />
''Unrelated MEL scripting help located here: [http://stores.lulu.com/nickpisca YSYT]. <br />
[[Category:CSharp]]</div>
Nickpisca