views:

68

answers:

1

Hi, I am working on an iPhone app and I am trying to make something that has to do with line-circle collision detection. I am using the slope of the line and checking if the coordinates of a circle suffice the equation y = mx + b. But, with the current origin (0,0) at the top left it is a pain to get the slope. Any way I can convert the coordinates so the origin is in the center of the screen?

+1  A: 

Lets say your actual origin is at 200,200 in screen coordinates. Why not just subtract 200,200 from the points concerned before doing your calculation? You then do your calculations as if origin is 0,0. Slope won't change. BTW iPhone has plenty of power for trigonometry. I've done point intersection in a circle by comparing the distance from a point to the midpoint with the known radius of the circle. You could use a tangent to the circle with slope identical to the line you want to check to find the intersection of a line drawn from the midpoint and compare length to radius. Everything is in CGFloats anyway and I haven't been able to slow even a 3G down yet.

Adam Eberbach