Search for the radius of an ellipse based on its angle from the primary or secondary axis

I work with UE3 and make my HUD. I made it in the canvas and the round button. The problem is that on screens that are not square, the button is an ellipse. Therefore, this leads to problems detecting that the mouse is “above” the button or not.

This is due to the fact that the radius does not coincide with the entire ellipse, as is the case with a circle.

Underlined Question:

How can I determine the radius of an ellipse relative to a point (location of the mouse), given that I know:

  • The radius of the main and minor axis
  • The angle from the axis (both primary and minor) of the point (mouse location)
+4
source share
2 answers

The equation of the ellipse balanced on an axis (I am sure that your ellipse is aligned on an axis, i.e. your display matrix is ​​not inclined):

((xx 0 ) / a) 2 + ((yy 0 ) / b) 2 = 1

where the ellipse is in the center (x 0 , y 0 ), and its semiaxes are a and b.

If the equation is satisfied, then the point (x, y) is on the ellipse. Replace =1 with <1 and you will get the condition (x, y) inside the ellipse.

+4
source

In the simple case, when the ellipse is centered at the origin, and the major and minor axes are parallel to the x and y axes, respectively, then the ellipse can be parameterized by the equations x = a cos(t) and y = b sin(t) , where a and b are the main and the minor axis, and t is the angle that varies from 0 to 2pi. Therefore, in this case, to answer your question, the radius at an angle t is

r = sqrt( x^2 + y^2 ) = sqrt( a^2 cos^2(t) + b^2 sin^2(t) )

Now this can be complicated in the following ways:

(i) The ellipse is not centered on (0,0)

(ii) The main and minor axes are not parallel to the x and y axes, for example, because the major axis forms an angle t0 from the positive x axis.

(iii) a combination of (i) and (ii).

However, the above solution can also be applied to these cases with the right changes. For (i) subtract the center from x and y in the above equation to get the radius from the center point. For (ii) the equation above will hold for the variables x ', y', where (x ', y') ^ T = R (t0) (x, y) ^ T, where R (t0) is the matrix rotation that correctly orientates the ellipse. So, we form the equation above for x 'and y', then substitute the expressions for x and y, solving the above matrix equation.

+4
source

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


All Articles