GetDistance2D
Distance# = GetDistance2D(X1, Y1, X2, Y2)
 
Parameters:

    X1 = X coordinate of 1st point
    Y1 = Y coordinate of 1st point
    X2 = X coordinate of 2nd point
    Y2 = Y coordinate of 2nd poiint
Returns:

    Distance# = Distance between point 1 and point 2
 

      The GetDistance2D() function returns the distance between any two given points.



Mini Tutorial:


      This example uses the GetDistance2D function to calc the distance between the middle of screen and the mouse pointer.


  
; calc the center of the screen
  CircleX     =GetScreenWidth()/2
  CircleY     =GetScreenHeight()/2
  
; start of man program loop
  Repeat
     
   ; clear the screen to black (rgb(0,0,0)=black)
     Cls RGB(0,0,0)
     
   ; get the mouse pointers current position
     mx=MouseX()
     my=MouseY()
     
   ; draw a circle in the middle of the screen.
     CircleC CircleX,CircleY,10,true,RGB(255,0,0)
     
   ; draw line between the circle and the mouse pointer
     Line mx,my,CircleX,CircleY
     
   ; calc the distance (the hypotenuse) between the two points
     dist#=GetDistance2D(mx,my,CircleX,CircleY)
     
     
   ; draw the distance in the middle of the line
     x#=(mx+CircleX)/2
     y#=(my+CircleY)/2
     
   ; display the distance
     CenterText x#,y#,"Distance:"+Str$(dist#)
     
   ; show the screen to the user
     Sync
     
   ; repeat UNTIL the ESC key is pressed
  Until EscKey()=true
  

 
Related Info: GetAngle2D | GetDistance3D | Sqrt :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com