Welcome, guest | Sign In | My Account | Store | Cart

In early 1600 Johannas Kepler conclude that all the planets in the solar system move in elliptical orbits with the sun at a focus, thus, the importance of ellipse in science. Ellipse is a Python program for students and tutors at higher levels of education . There are two equations of an ellipse : x^2/a^2 + y^2/b^2 and: x^2/b^2 + y^2/a^2 the foci are on the x axis or y axis. From Ellipse program the student will be able to sketch the ellipse, by drawing a box with (a) and (-a) units on the major axis and ( b) and (-b) units on the minor axis. Since Ellipse program determine the values of a and b and the position of the foci c. c = Square-Root (a^2 – b^2)

Python, 55 lines
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57``` ```#On the name of ALLAH #Author : Fouad Teniou #Date : 23/09/08 #Version 2.4 import math as m Class Ellipse: """ Class that represent an ellipse """ def __call__(self,**kargs): # ** allows to convert from keywords to dictionary """ Python run __call__ method for function call expressions applied to instance """ self.kargs = kargs self._a = "%2.1f" self._b = chr(253) self._c = self._a% m.sqrt(self.kargs.get('a')) self._d = self._a% m.sqrt(self.kargs.get('b')) self._e = self._a% m.sqrt(abs(self.kargs.get('a') - self.kargs.get('b')) self._f = self._a% m.sqrt(abs(self.kargs.get('b') - self.kargs.get('a')) #Determine if Ellipse equation should be displayed, based on keys’ values if (len(kargs) == 2 and self.kargs.has_key('a') and self.kargs.get('a') != 0 and self.kargs.has_key('b') and self.kargs.get('b') !=0 and self.kargs.get('a') != self.kargs.get('b')): if self.kargs.get('a') > self.kargs.get('b'): self._e else: self._f #raise ValueError if one or more of keys’ values are not appropriate else: raise ValueError, \ ("\n self.kargs.get('b') return "\n Created by Fouad Teniou on Tue, 23 Sep 2008 (MIT)

### Required Modules

• (none specified)