usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< PreviousNext >>

Code to Animate an Image Body through an Ellipse in Python



Using the Equation of an Ellipse in Python

Ellipses are represented by the general equation

(x - h)2   +   (y - k)2   =   1
a2 b2
where (h, k) is the centre (point of intersection of the major and minor axes) of the ellipse; and a & b are the major and minor radii (1/2 the axis) respectively.
Quadratic Points

Solving for y, we have:

(y - k)2   =   1   -   (x - h)2
b2 a2
(y - k)2   =   a2 - (x - h)2
b2 a2
(y - k)2   =   b2[ a2 - (x - h)2 ]
a2
(y - k) = ±b√(a2 - (x - h)2)
a

y = k ± b/a√(a2 - (x - h)2)



Code to Animate a Body through the Trajectory of an Ellipse in Python

To make a graphic (dot) travel in an circular path, all we have to do is increment x in the range of h - a ≤ x ≤ h + a; and get the corresponding y value using the equation of the ellipse.

Create a new file; File, New File.
Call it EllipticalPath.py.
Type out the adjoining Python / Turtle code for animating an image body through the path of an ellipse.









<< PreviousNext >>