ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

DistanceToPoint

Calculates the distance between two points

Source

<Extension()> _
Public Function DistanceToPoint( _
   ByVal PointA As Point, ByVal PointB As Point) As Single
    Return Math.Sqrt( _
       (PointA.X - PointB.X) ^ 2 + _
       (PointA.Y - PointB.Y) ^ 2)
End Function

Example

' Triangle of pythagoras a^2=b^2+c^2
Dim ptA As New Point(3, 4)
Dim ptB As New Point(5, 6)
MsgBox(ptA.DistanceToPoint(ptB))

Author: Doc Tari

Submitted on: 13 mrt. 2008

Language: VB

Type: Drawing.Point

Views: 3969