0

I am implementing a little game in c with sdl2/sdl_gfx for an assignment where you need to avoid the arcs coming at you (in the center) by moving the little cursor under the white circle (it moves around the circle).

My question is simple: what can be an efficient implementation to detect if my cursor intersect an arc?

For each arcs have : the center point (x,y), starting and ending radius, radius. Which are the arguments of:

int arcRGBA(SDL_Renderer *renderer, Sint16 x, Sint16 y, Sint16 rad, Sint16 start, Sint16 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a)

For my cursor (the little triangle under the circle) i have : the coordinates of the triangle.

int filledTrigonRGBA(SDL_Renderer *renderer, Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Sint16 x3, Sint16 y3, Uint8 r, Uint8 g, Uint8 b, Uint8 a)

Having this information, i thought about using Lines of my triangle to detect if it intersects with an arc. But i dont know how to implement it with the maths involved in it.

enter image description here

Note: The Arcs are moving and their coordinates are updated each frame. I only need to know the implementation to detect an intersection.

Lynn
  • 121
  • 8
  • 25
  • You say you have the arcs center point coordinates. So they are not concentric?I ask because to me (potentially too myoptic) it looks like the arcs are concentric at the little whitle disc. – Yunnosch Dec 25 '19 at 22:41
  • Yes, they all have the same center point. The middle of the screen – Lynn Dec 25 '19 at 22:42
  • Can you compute the distance from the arc's center to the cursor? What does it mean if that is very close to the radius of the arc? – Scott Hunter Dec 25 '19 at 22:42
  • But then the coordinates are redundant, which seems to indicate that you did not get the objectives right - or failed to explain them correctly and in enough detail, which seems more likely. – Yunnosch Dec 25 '19 at 22:43
  • @ScottHunter hmmm never thought about that, it can work. I have to try that lol – Lynn Dec 25 '19 at 22:44
  • @Yunnosch i'm not a pro yet, and yeah its probably redundant in my code. – Lynn Dec 25 '19 at 22:46
  • 1
    @Hazel: or `arcRGBA` needs the center point, even if all of the arcs have the same one. – Scott Hunter Dec 25 '19 at 22:49
  • @ScottHunter hey, like you said, i can compute the distance and detect if the arc radius reach that distance, but what if my cursor point is not touching the arc even if the arc radius is at the same level as my point. I can't detect that. – Lynn Dec 26 '19 at 01:41

1 Answers1

0

Solved it with !!!!!!!

This topic enter image description here

Lynn
  • 121
  • 8
  • 25
  • Hmmm, Is the true goal to find 1) if the cursor is in the arc sector (the pie wedge) or 2) if the triangle cursor intersects the arc (the outer rim)? This answers does solve #1, yet the question posed "Compute intersection between Line and Arc" looks like #2 and not solved here. – chux - Reinstate Monica Dec 26 '19 at 09:49
  • It does when combined w/ comparing the distance from the arc centerpoint is the same & the arc radius. – Scott Hunter Dec 26 '19 at 12:55
  • @ScottHunter exactly – Lynn Dec 26 '19 at 20:50