C # version
/***** Distance from a point to a straight line ***
* The Linear Equations of points (x1, Y1) and points (X2, Y2) are: Kx-y + (x2y1-x1y2)/(x2-x1) = 0
* Set the straight line slope to k = (y2-y1)/(x2-x1), c = (x2y1-x1y2)/(x2-x1)
* The distance from point P (x0, y0) to the straight line AX + by + c = 0de is: D = | ax0 + by0 + c |/SQRT (A * A + B * B)
* The shortest distance from a vertex (X3, Y3) to a straight line between a vertex (x1, Y1) and a vertex (X2, Y2) is:
* Distance = | K * X3-Y3 + c |/SQRT (K * k + 1)
*/
Public static double getmindistance (ipoint pt1, ipoint pt2, ipoint pt3)
{
Double Dis = 0;
If (pt1.x = pt2.x)
{
Dis = math. Abs (pt3.x-pt1.x );
Return DIS;
}
Double linek = (pt2.y-pt1.y)/(pt2.x-pt1.x );
Double linec = (pt2.x * pt1.y-pt1.x * pt2.y)/(pt2.x-pt1.x );
Dis = math. Abs (linek * pt3.x-pt3.y + linec)/(math. SQRT (linek * linek + 1 ));
Return DIS;
}
Vb version
Public Function getverticalpoint (byval X1 as double, byval Y1 as double, byval X2 as double, byval Y2 as double, byval X3 as double, byval Y3 as double, byref X as double, byref y as double) as Boolean
'(X, y) returns the vertical foot. (x1, Y1) is the test point. (X2, Y2) (X3, Y3) is the linear point.
On Error goto proc_error
Dim result as new mapxlib. Point
If X2 = X3 then' vertical line
X = x2
Y = Y1
Getverticalpoint = true
Exit Function
Else
Dim KK as double
Kk = (Y3-Y2)/(X3-X2)
X = (Y1-y2 + KK * X2 + (1/KK) * X1)/(1/KK) + KK)
Y = KK * X-X2 * KK + y2
Getverticalpoint = true
Exit Function
End if
Getverticalpoint = false
Exit Function
Proc_error:
Msgbox err. Description
End Function