Jump to content
Sign in to follow this  
brians200

Finding roads inside of a rotated ellipse

Recommended Posts

Hello,

I am trying to find all the roads inside of rotated ellipse. The ellipse comes from a map marker that is created by the user.

I have tried implementing the answer from here to determine if a point is in an ellipse.

 
_u = cos(_angle) * (_ellipseX - _pointX) + sin(_angle) * (_ellipseY - _pointY);
_v = -sin(_angle) * (_ellipseX - _pointX) + cos(_angle) * (_ellipseY - _pointY);

_dSqr = (_u/_sizeA)*(_u/_sizeA) + (_v/_sizeB)*(_v/_sizeB);
_dSqr <= 1;

However, when I try this, it only works when the angle is 0, 90, 180, or 270.

Any other angle produces what I can only describe as a scissor effect. Here is a series of pictures from 0 to 90 degrees, increasing the angle by 15 degrees.

The green dots are the roads that the code is returning as "in the ellipse".

0 Degrees

tHmLiwd.jpg

15 Degrees

3CTxtz9.jpg

30 Degrees

GHyeKr0.jpg

45 Degrees

srsKP1O.jpg

60 Degrees

cXxbCmt.jpg

75 Degrees

MtN6pC4.jpg

90 Degrees

zxp4dQZ.jpg

I also tried implementing the answer from here, and got the same results

_left = (cos(_angle)*(_pointX - _ellipseX) + sin(_angle) * (_pointY - _ellipseY))/_sizeA;
_right = (sin(_angle)*(_pointX - _ellipseX) - cos(_angle) * (_pointY - _ellipseY))/_sizeB;

_left*_left + _right*_right <= 1;

Does anybody know what is wrong with the math? The angle and ellipse size are taken from the marker using markerDir and getMarkerSize

Share this post


Link to post
Share on other sites

Hi,

it seems that your ellipse is mirrored. What happens if you put negative value to the angle? Eg.

_angle = _angle * (-1)

regards.Väinämöinen

Share this post


Link to post
Share on other sites

That fixes the problem!

I guess it is because as you increase your angle when using North/South/East/West, you rotate clockwise. However, when working with a unit circle, you rotate counter clockwise.

YEFT0Li.gif

Thanks for your help, Väinämöinen.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×