Results 1 to 10 of 21

Thread: Circle vs pie segment collision detection

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    hmm...the code seems to be returning true for me most of the time, so I get flickering energy discharges at the target as it thinks the circle and pie are intersecting lots...

    I am setting up the circle and pie like this:

    Code:
        BeamHasHitPlayer := False;
    
        if Assigned(FPlayer) then
        begin
          Circle.c := G2Vec2(FPlayer.x,FPlayer.y);
          Circle.r := FPlayer.Width * 0.4;
    
          Pie.c := G2Vec2(aSentry.x,aSentry.y);
          Pie.r := aSentry.BeamRange;
          Pie.AngStart := aSentry.Angle - aSentry.BeamWidth/2;
          Pie.AngEnd   := aSentry.Angle + aSentry.BeamWidth/2;
    
          BeamHasHitPlayer := CircleVsPieIntersect(Circle,Pie);
        end;
    Any ideas?

    If it helps, the beam width is 50 degrees wide, and the screen coordinate system being used is this (if it makes a difference?):

    Code:
    0,0
    +----------------------  +X
    |
    |
    |
    |
    |
    |
    |
    
    +Y
    cheers,
    Paul

  2. #2
    The function assumes that the angles are in radians so you might need to multiply your degree angles by (Pi / 180).
    EDIT: Here's my test app.
    Attached Files Attached Files
    Last edited by Dan; 28-10-2010 at 05:48 AM.

  3. #3
    Quote Originally Posted by Dan View Post
    The function assumes that the angles are in radians so you might need to multiply your degree angles by (Pi / 180)
    <Drumroll...> that was it...it is now working, sweet!! thanks mate

    <gives a beer>

    Now that it is working, I might convert the function to use my plain, vanilla records so lesser versions of Delphi can compile the code too

    cheers,
    Paul

  4. #4
    it was an interesting problem to solve.

  5. #5
    Here is a picture of the Sentry zapping the user character



    Thanks again

    cheers,
    Paul

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •