KB10329 - Measure shortest distance between a line and a point.
' place DKcomponent on the form just to be sure that an object will be connected
Public ProjectionList As New TatukGIS_DK.XGIS_ProjectionList()
Const Pi = 3.14159265358979
Dim GISUtils as new XGIS_Utils
--- code
Private Sub My_procedure()
Dim proj As TatukGIS_DK.XGIS_ProjectionAbstract
Dim src As New TatukGIS_DK.XGIS_Coordinate()
Dim dst As New TatukGIS_DK.XGIS_Coordinate()
Dim unt As New TatukGIS_DK.XGIS_Units()
proj = ProjectionList.FindEx("UTM")
proj.SetUp(0, 0, 0, 0, 0, 0, 17, 0)
'coordinates are:
'Point 1
'Lat: 2626.9222755
'Lng: 8143.1208638
' 8143.1208638 = 81 deg 43.1208638 = 81 + 43.1208638 / 60
' and we must express in radians so * Pi / 180
src.Prepare((81 + 43.1208638 / 60) * Pi / 180, (26 + 26.9222755 / 60) * Pi / 180, 0)
dst = proj.Projected(src)
'plug in the results to a textbox for display
TextBox1.Text = dst.X
TextBox2.Text = dst.Y
End Sub
The trigonometry equation to calculate the distance and to indicate on which side of the line the point is located would be as follows:
ptA - starting point
ptB - ending point
ptG - point to test
distance = GISUtils.GisLine2Point(ptA, ptB, ptG)
res = (ptG.Y - ptA.Y) *(ptB.X - ptA.X) * (ptG.X - ptA.X) * (ptB.Y -ptA.Y)
if res > 0 then point is on the left
if res = 0 then point is in-line
if res < 0 then point is on the right
Created: November 21, 2003, Modified: August 03, 2015