Draw an Ellipse

Introduction

You can draw an ellipse by drawing a circle tilted towards or away from the viewer.

Project #1

Draw an ellipse in the x,y plane (z = 0).

image missing

Project #2

Create and interactive program to draw an ellipse in the x,y plane (z = 0). Ask the user to input:

Design Notes, etc.

1. Because we are drawing individual pixels, round x,y coordinates to integer values.

2. You only need to calculate 1/4 if the points on the surface of the ellipse. The ellipse is symmetrical around the x and y axes when drawn in the xy plane (z = 0).

              +y
               |
      (-x,y)   |   (x,y)
               |
    -x --------+-------- +x
               |
     (-x,-y)   |   (x,-y)
               |
              -y

3. Pseudo code - draw an ellipse

Note: This code tilts the circle around the X axis.

win = create_a_drawing_window()
for x in [0,1,2,3,4, ..., r]:
    y = calculate_ellipse_y_coord(x,r,θ)
    draw_a_point(win,x,y)
    draw_a_point(win,x,-y)
    draw_a_point(win,-x,y)
    draw_a_point(win,-x,-y)

4. The X coordinate should never be larger that R.

Graphics Library

Use graphics.py to draw the ellipse. Click HERE for more information. (download, install, documentation, ...)

Circle Equation with Radius R

x2 + y2 = r2

Ellipse Equation with Radius R and Tilt Angle θ

x2/r2 + y2/(r2cos2(θ)) = 1
  or
x2 + y2/cos2(θ) = r2
  or
y2 = cos2(θ) * (r2 - x2)

Equation From: Calculating angle of circle to produce given ellipse

How it Works