How to check if point is in elliptical sector without float-point arithmetic?

72 Views Asked by At

How can I check whether point lies in elliptical sector without float-point arithmetic if I know a and b from the ellipse equation, start and end angles of the sector and x, y coordinates of the point.

1

There are 1 best solutions below

0
On BEST ANSWER

The question is to check if the inequalities $$ (x/a)^2 + (y/b)^2 \le 1, \tag{1}$$ $$ \tan(t_1) \le y/x \le \tan(t_2). \tag{2}$$ hold for the integers $\, x, y \,$ where $\, a,b>0 \,$ are positive integers and $\,t_1, t_2\,$ are angles in degrees (or other units). We suppose we have available sine/cosine tables $\, S(t) = \sin(t)\, r, \quad C(t) = \cos(t)\, r \,$ where $\, r>0 \,$ is an integer radius of a circle. The first inequality is equivalent to $$ b^2 x^2 + a^2 y^2 \le a^2b^2 \tag{3}$$ while the second is equivalent to $$ S(t_1)x \le C(t_1)y, \quad C(t_2)y \le S(t_2)x \tag{4}$$ but we have to be careful if $\, x<0, y<0 \,$ or $\,C(t_1)<0,\, C(t_2)<0 \,$ and special case code to deal with that is probably the best idea.