LineIntersectCircle
Result = LineIntersectCircle(X1, Y1, X2, Y2, CircleX, CircleY, Radius, [CalcImpacts=0])
 
Parameters:

    X1 = The starting X coordinate of the line
    Y1 = The starting Y coordinate of the line
    X2 = The ending X coordinate of the line
    Y2 = The ending Y coordinate of the line
    CircleX = X-position of the circle
    CircleY = Y-position of the circle
    Radius= radius of the circle
    [CalcImpacts=0] = Flag to calc the intersection points or normals
Returns:

    Result
 

      LineIntersectCircle checks if a line intersects a circle. The function returns the number of impacts the line makes with the circle edges. The function offers various detection modes, when can be controlled using the CalcImpacts parameter.


     CalcImpacts Settings:

      The LineIntersectCircle treats that calc impacts parameter as 4 bit switches. Bits 0 & 1 control the first and second impacts points and bits 2 & 3 control the normals. Giving us 16 possible combinations.

      Here's the first 8,
      0 = Don't calculate any impact coordinates or normals
      1 = Calc first impact coordinate.
      2 = Calc second impact coordinate (if it exists).
      3 = Calc the first and second impacts
      4 = Calc Normal of the first impact.
      1+4 = Calc Impact and Normal of first impact.
      2+4 = Calc Impact of Second point and Normal of first.
      1+2+4 = Calc Impact of First + Second point and Normal of first.
      1+2+4 = Calc Impact of First + Second point and Normal of first.
      8 = Calc the Normal of the second impact.
      1+8 = Calc first impact, with the Normal of the second impact.




FACTS:


* When impacts coordinates are required, they can be accessed using the GetIntersectX#(), GetIntersectY#() and the GetNormalX# & Y functions respectively.



Mini Tutorial:


Show the use of LineIntersectCircle

  
; init the position & size of our test circle
  CircleX = GetScreenWidth() *0.5
  CircleY = GetScreenHeight() *0.5
  
; circles radius
  CircleRadius =40
  
; Start of Repeat/Until loop
  Repeat
     
   ; Clear the Screen to black (rgb(0,0,0)= black)
     Cls RGB(0,0,0)
     
   ; Display Message
     Print "Checking if line Intersects Circle"
     
   ; Draw a circle
     Circle CircleX, CircleY, CircleRadius, false
     
     
   ; Get the mouses position
     mx=MouseX()
     my=MouseY()
     
   ; Draw a line from 0,0 to Mouse position
     Line 00, mx,my
     
   ; Check for Intersection
     If LineIntersectCircle(0 , 0, Mx, My, CircleX, CircleY, CircleRadius,1)
      ; The line has hit the circle so we display a message
        Print "Line Intersected Circle"
        Circle GetIntersectX#(0),GetIntersectY#(0),5,true
     EndIf
     
   ; display the screen
     Sync
     
   ; Check the ESC key and only Loop back to the previous repeat
   ; statement if the key was not being pressed
  Until EscKey()=true
  
  
  
  
  





 
Related Info: CirclesIntersect | GetIntersectX# | GetIntersectY# | GetNormalX# | GetNormalY# | LineIntersectRect | LinesIntersect | PointInBox | PointIntersectCircle :
 


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