Not Yet Answered # creating a ellispse at any aspect angle

Nuez_Jr alc6379 105

0

hi all ,

i have to create an ellispe the inputs are

major axis , minor axis , and the angle of the major axis

the ellipse needs to be tilted.

thanks

aviral

Construct the formula for the ellipse in standard position, and then use an affine transformation to rotate it. Better yet, if you need to draw it to screen, construct the parametric formula for the ellipse and transform that.

A circle in standard position is given thus:

x = r cos(t)

y = r sin(t)

t = 0..1

Change it to an ellipse by substituting the major and minor axes into the position of r in the x and y equations:

x = r_maj * cos(t)

y = r_min * sin(t)

Then multiply by the transformation matrix

[ [ cos(a), sin(a)] [-sin(a), cos(a)] ]

To rotate the whole thing counterclockwise by angle 'a'.

<r_maj*cos(t), r_min*sin(t)> * [[cos(a),sin(a)][-sin(a),cos(a)]] =

Which, after tedious and error-prone-when-done-by-hand matrix multiplication, gives

x = r_maj*cos(t)*cos(a) + r_min*sin(t)*-sin(a)

y = r_maj*cos(t)*sin(a) + r_min*sin(t)*cos(a)

This is just a quick answer; there are probably better and faster ways to get the points on an ellipse, but this'll definitely draw the right shape. If you're drawing pixel-by-pixel the line may look a bit chunky in places, since you'll be simply painting every pixel <x, y> ever occupies for 0<=t<=1. There are probably algorithms extant to smooth that behavior out and produce better "single-pixel-wide" lines.

0

Again, don't just blatantly post questions like this. Further posts of these nature (ie, you simply posting a question that looks like homework, but lacking any code you've written, will be closed, no questions asked.

We're here to help you learn, not to cheat.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

I am currently creating a simulation of a pizza ordering system in object oriented program. I have some question. the instruction and guideline is long but I will try and cut it down a lot. the instruction is to create a program that simulate a pizza restaurant using ...

```
#include <stdio.h>
int main(void)
int movieChoice;
int seatNum;
int seatPlan[5][10] = { 0 };
int rows, cols;
char space;
void seatDisplay(int a[][10]);
void seatNew(int n[][10]);
void seatDisplay(int a[][10]) { //this function shows the seat plan
for (int i = 0; i<5; i++) {
for (int j = 0; j<10; j++) ...
```

I have this tree format.

```
> myapp->
> setup.py
> tests ->
> test_myapp.py
> myapp ->
> __init__.py
> myapp.py
```

And from test_myapp.py, I am calling: `from myapp import myapp`

and when I run`python setup.py test`

I am getting `No module named 'myapp'`