Setting the origin to the center of the screen instead of the upper left screen? (Iphone)

I am working on an iPhone application and I am trying to do something related to line collision detection. I use the slope of the line and check if the coordinates of the circle are sufficient for the equation y = mx + b. But, with the current origin (0,0) in the upper left corner, it is a pain to get a slope. In any case, can I convert the coordinates so that the origin is in the center of the screen?

+3
source share
1 answer

Suppose your actual origin is 200,200 in screen coordinates. Why not just subtract 200,200 from the corresponding points before doing the calculation? Then you do your calculations as if the start was 0.0. The slope will not change. BTW iPhone has enough power for trigonometry. I made the intersection of the points in a circle, comparing the distance from the point to the middle with the known radius of the circle. You can use the tangent to the circle with a slope identical to the line you want to check to find the intersection of the line taken from the midpoint and compare the length with the radius. All the same in CGFloats, and I still could not slow down even 3G.

+2
source

Source: https://habr.com/ru/post/1745914/


All Articles