| | |
creating a ellispse at any aspect angle
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
•
•
Originally Posted by aviral82
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.
![]() |
Similar Threads
- CS Major troubles/Confidence (Computer Science)
- issue with Tkinter canvas widget (Python)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- problem in creating a rectangle at a angle (C++)
- maths for 3d? (HTML and CSS)
Other Threads in the C Forum
- Previous Thread: text to numbers, numbers to text
- Next Thread: NEED HELP ON TOPIC : "INTELLECTUAL PROPERTY & HR EXPERTISE DATABASE IN S/W COMPANY"
| Thread Tools | Search this Thread |
Tag cloud for C
* adobe api append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global gtkgcurlcompiling gtkwinlinux highest homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list lowest matrix meter microsoft mqqueue multi mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scheduling segmentationfault send single socketprogramming spoonfeeding stack standard strchr string student suggestions system test testautomation unix urboc user whythiscodecausesegmentationfault win32api windows.h windowsapi






