2
votes

I am trying to draw a rotated ellipse not centered at the origin (in c++).

so far my code "works":

        for (double i = 0; i <= 360; i = i + 1) {

            theta = i*pi / 180;

            x = (polygonList[compt]->a_coeff / 2)  * sin(theta) + polygonList[compt]->centroid->datapointx;
            y = (polygonList[compt]->b_coeff / 2)  * cos(theta) + polygonList[compt]->centroid->datapointy;

            xTmp = (x - polygonList[compt]->centroid->datapointx)* cos(angle1) - (y - polygonList[compt]->centroid->datapointy)*sin(angle1) + polygonList[compt]->centroid->datapointx;
            yTmp = (x - polygonList[compt]->centroid->datapointx)* sin(angle1) + (y - polygonList[compt]->centroid->datapointy)*cos(angle1) + polygonList[compt]->centroid->datapointy;
      }

PolygonList is a list of "bloc" which will be replaced by an ellipse of same area.

My issue is that the angles are not quite exact, as if I had to put a protractor that'd fit the shape of my ellipse, the protractor would obviously get squeezed, and so would be the angles (is that clear ?)

Here is an example: I am trying to set a point on the top ellipse (E1) which would be lying on a line drawn between the centroid of E1, and any point on the second ellipse (E2).On this example, the point on E2 lies at an angle of ~220-230 degree. I am able to catch this angle, the angle seems ok.

case 1

The problem is that if I try to project this point on E1 by using this angle of ~225 degree, I end up on the second red circle on top. it looks like my angle is now ~265 degree, but in fact, if I shape the protractor to fit in my ellipse, I get the right angle (~225) ,cf img 2)

case 2

it is a bit hard to see the angle on that re-shaped protractor, but it does show ~225 degree.

My conclusion is that the ellipse is drawn like if I had to drew a circle and then I'd compress it, which changes the distance between the angles.

Could someone tell me how I could fix that ?

PS: to draw those ellipses I just use a for loop which plots a dot at every angle (from 0 to 360). we clearly see on the first picture that the distance between the dots are different whether we are at 0 or at 90 degree.

2
What exactly are you trying to ask here? What do you mean your angles are not right - the angles are right, you're just looking at 2 different definitions. In one case you look at the polar angle and in the other you're thinking about the "angle" used to parametrise the ellipse. But you seem to be drawing a rotated ellipse just fine.Qubit
Sorry my question was probably unclear. I am also confused as I am not really confident talking geometry. I guess What I am trying to ask is how should I define X and Y for each dot 360 points representing my ellipse.TheEpok
You seem to have 360 dots, they're just not spaced uniformly on the ellipse. What exactly is wrong with the ones you have?Qubit
Ideally, I would like 360 dots; each one of them spaced by 1 degree of angle. on my example they are not spaced by 1 degree of arcTheEpok
I see, so basically you want dots at the intersections of the lines with the ellipse in your first picture (possibly denser, but that's the basic idea)? In that case, maybe that is exactly what you should try to solve?Qubit

2 Answers

0
votes

your parametrisation is exactly that, a circle is a case of ellipse with both axes are equal. It sounds like you need use rational representation of ellipse instead of standard: https://en.m.wikipedia.org/wiki/Ellipse

0
votes

So, I've asked the question above so that I could find a possible overlap between 2 ellipses by checking the distance between any point on E2 and its projection on E1: if the distance between the centroid of E1 and the projected dot on E1 is larger than the distance between the centroid of E1 to a dot on E2 I'll assume an overlap. I reckon this solution has never been tried (or I haven't search enough) and should work fine. But before working I needed to get those angles right.

I have found a way to avoid using angles and projected dots, by checking the foci:

  • the sum of the distance between the focus A and B to any point around an axis is constant (let's call it DE1 for E1).
  • I then check the distance between my foci and any point on E2. If that distance becomes less than DE1, I'll assume a connection.

So far it seems to work fine :)

I'll put that here for anyone in need.

Flo