Quantcast
Channel: Question and Answer » curves
Viewing all articles
Browse latest Browse all 18

Check if a point is touching a user drawn curve in HTML5 canvas

$
0
0

I am having trouble detecting whether a ball is colliding with a red curve. The curve below is an example of what a user may draw on to the canvas. I can’t think of any fast ways to detect collision between a green ball and the red line here.

example of curve

I have thought of checking the color of the pixel every tick at the location of the ball, but this is very slow and the round ball will fill more than just the centre pixel. I have also thought about logging every single X, Z point that the curve drawer has inserted and then checking if the ball is near to the point, but this also seems like a bad method.

From a red curve drawn on to the screen by a user, what is the best way to detect whether a point is colliding with the red line? Shall I store every single point of the red curve or check the color of the pixel at the point to see if it is red or not?


Viewing all articles
Browse latest Browse all 18

Trending Articles