def __init__(self, x=None, y=None, z=None): self.x = 0 self.y = 0 self.z = 0 if x is not None: if is_num.isNumber(x): self.x = x if y is not None: if is_num.isNumber(y): self.y = y if z is not None: if is_num.isNumber(z): self.z = z
def __init__(self,x = None,y = None,z = None): self.x = 0 self.y = 0 self.z = 0 if x is not None: if is_num.isNumber(x): self.x = x if y is not None: if is_num.isNumber(y): self.y = y if z is not None: if is_num.isNumber(z): self.z = z
def __init__(self, radius, mass): #time to sanitize if is_num.isNumber(radius): self.radius = float(radius) else: raise IncorrectInput("The first argument must be a number") if is_num.isNumber(mass): self.mass = float(mass) else: raise IncorrectInput("The second argument must be a number") self.volume = 4 / 3 * math.pi * self.radius**3 self.area = 4 * math.pi * self.radius**2 self.averageDensity = self.volume / self.mass
def __init__(self,focal,vector_normal,radius): #first I need to sanitize the data if isinstance(focal,coordinate.Coordinate): self.focal_one = focal self.focal_two = focal else: raise IncorrectInput("The first argument must be a Coordinate") if isinstance(vector_normal,coordinate.Vector): self.vector_normal = vector_normal else: raise IncorrectInput("The second argument must be a Vector") #distance is 2r for a circle and r + r' for all ellispes #also 2* semimajoraxis if is_num.isNumber(radius): self.semimajoraxis = float(radius) else: raise IncorrectInput("The fourth argument must be a number") self.plane = coordinate.Plane(self.vector_normal,focal) self.vector = self.focal_one - self.focal_two #this vector is from focal_one to focal_two self.eccentricity = self.vector.distance/(self.semimajoraxis * 2) if self.eccentricity > 1: raise IncorrectInput("These inputs do not produce a valid Ellipse") self.semiminor_axis = math.sqrt(self.semimajoraxis**2 * (1-self.eccentricity**2)) self.area = math.pi * self.semimajoraxis * self.semiminor_axis
def __init__(self,radius,mass): #time to sanitize if is_num.isNumber(radius): self.radius = float(radius) else: raise IncorrectInput("The first argument must be a number") if is_num.isNumber(mass): self.mass = float(mass) else: raise IncorrectInput("The second argument must be a number") self.volume = 4/3 * math.pi * self.radius**3 self.area = 4 * math.pi * self.radius**2 self.averageDensity = self.volume/self.mass
def plot_specific_angles(self,figure,axis_one,axis_two,colour,theta_values,size = None): #this is another testing method that plots whatever theta values you want #this is used by orbit when it plots the orbit with respect to time #because ellipse itself has no concept of time built in if not isinstance(figure,plt.Subplot): raise IncorrectInput("The first input must be a figure") if (self.focal_one.getDirection(axis_one) == None or self.focal_one.getDirection(axis_two) == None): raise IncorrectInput("The second and third inputs must be vaild axis names") if size is None: size = 1 elif not is_num.isNumber(size) or size <= 0: raise IncorrectInput("The fifth input must be a positive number") coordinates = self.get_coordinates(theta_values) one_values = [] two_values = [] for a in coordinates: one_values.append(a.getDirection(axis_one)) two_values.append(a.getDirection(axis_two)) figure.scatter(one_values,two_values,color = colour)
def plot(self,figure,axis_one,axis_two,colour,size = None,points = None): #this plots the ellipse with a uniform distance of angle betwen points #note that the angle is with respect to a focal_point and will not be uniform over the ellipse #sanitize data if not isinstance(figure,plt.Subplot): raise IncorrectInput("The first input must be a figure") if (self.focal_one.getDirection(axis_one) == None or self.focal_one.getDirection(axis_two) == None): raise IncorrectInput("The second and third inputs must be vaild axis names") if points is None: points = 1000 #default if size is None: size = 1 elif not is_num.isNumber(size) or size <= 0: raise IncorrectInput("The fifth input must be a positive number") theta_values = numpy.linspace(0,math.pi*2,points) coordinates = self.get_coordinates(theta_values) one_values = [] two_values = [] for a in coordinates: one_values.append(a.getDirection(axis_one)) two_values.append(a.getDirection(axis_two)) figure.scatter(one_values,two_values,s = size,color = colour)
def get_relative_speed(self, distance): #I never use this but I could to find out the speed at different points around the orbit if not is_num.isNumber(distance): raise IncorrectInput("The first argument must be a number") return math.sqrt(2 * (self.specific_orbital_energy + (self.standard_gravitation_parameter / distance)))
def flux(self,distance): #never gets used if is_num.isNumber(distance): distance = float(distance) else: raise IncorrectInput("The first argument must be a number") return self.luminosity/(4*math.pi*distance)
def flux(self, distance): #never gets used if is_num.isNumber(distance): distance = float(distance) else: raise IncorrectInput("The first argument must be a number") return self.luminosity / (4 * math.pi * distance)
def __mul__(self,other): #this accepts Coordinate * Constant = Coordinate if is_num.isNumber(other): x = self.x * other y = self.y * other z = self.z * other return Coordinate(x,y,z) else: raise IncorrectMultiplication("You must multiply a Coordinate by a Constant")
def rotate(self,angle): #if you want to rotate something on a plane then use Plane's rotate method #this rotates the current vector around 0,0,0 (which I do not remember if that goes without saying) if not is_num.isNumber(angle): raise IncorrectInput("The first agrument must be a number") x = (self.x * math.cos(angle)) - (self.y * math.sin(angle)) y = (self.x * math.sin(angle)) + (self.y * math.cos(angle)) return Vector(x,y,self.z)
def __init__(self,focal_one,focal_two,vector_normal,distance,size = None): #first I need to sanitize the data if isinstance(focal_one,coordinate.Coordinate): self.focal_one = focal_one else: raise IncorrectInput("The first argument must be a Coordinate") if isinstance(focal_two,coordinate.Coordinate): self.focal_two = focal_two else: raise IncorrectInput("The second argument must be a Coordinate") #distance is 2r for a circle and r + r' for all ellispes #also 2* semimajoraxis if is_num.isNumber(distance): self.semimajoraxis = float(distance)/2 else: raise IncorrectInput("The third argument must be a number") #the inclination angle is in radians if isinstance(vector_normal,coordinate.Vector): #this causes problems for circles self.vector_normal = vector_normal else: raise IncorrectInput("The fourth argument must be a Coordinate") self.plane = coordinate.Plane(self.vector_normal,self.focal_one) self.vector = self.focal_one - self.focal_two #this vector is from focal_one to focal_two self.eccentricity = self.vector.get_distance()/(self.semimajoraxis * 2) if self.eccentricity > 1: raise IncorrectInput("These inputs do not produce a valid Ellipse") self.semiminor_axis = math.sqrt(self.semimajoraxis**2 * (1-self.eccentricity**2)) self.area = math.pi * self.semimajoraxis * self.semiminor_axis if size is None: self.size = 1 elif is_num.isNumber(size): self.size = float(size) else: raise IncorrectInput("The six argument must be a number")
def __div__(self, other): #This accepts Vector / Constant = Vector if is_num.isNumber(other): if other != 0: inverse = 1 / float(other) return self * inverse else: raise DivideByZero("You cannot Divide by Zero") else: raise IncorrectDivision("You must divide a Vector by a Constant")
def __div__(self,other): #This accepts Vector / Constant = Vector if is_num.isNumber(other): if other != 0: inverse = 1/float(other) return self * inverse else: raise DivideByZero("You cannot Divide by Zero") else: raise IncorrectDivision("You must divide a Vector by a Constant")
def rotate(self, angle): #if you want to rotate something on a plane then use Plane's rotate method #this rotates the current vector around 0,0,0 (which I do not remember if that goes without saying) if not is_num.isNumber(angle): raise IncorrectInput("The first agrument must be a number") x = (self.x * math.cos(angle)) - (self.y * math.sin(angle)) y = (self.x * math.sin(angle)) + (self.y * math.cos(angle)) return Vector(x, y, self.z)
def __mul__(self, other): #this accepts Coordinate * Constant = Coordinate if is_num.isNumber(other): x = self.x * other y = self.y * other z = self.z * other return Coordinate(x, y, z) else: raise IncorrectMultiplication( "You must multiply a Coordinate by a Constant")
def __init__(self,vector,intensity): if isinstance(vector,coordinate.Vector): self.vector = vector else: raise IncorrectInput("The first argument must be a Vector") if is_num.isNumber(intensity) and intensity > 0: self.intensity = intensity else: raise IncorrectInput("The second argument must be a positive number")
def __init__(self, vector, intensity): if isinstance(vector, coordinate.Vector): self.vector = vector else: raise IncorrectInput("The first argument must be a Vector") if is_num.isNumber(intensity) and intensity > 0: self.intensity = intensity else: raise IncorrectInput( "The second argument must be a positive number")
def rotate(self, other, angle): #this rotates an vector around the vector normal to the plane #returns a vector if not isinstance(other, Vector): raise IncorrectInput("The first input must be a Vector") if not is_num.isNumber(angle): raise IncorrectInput("The second agrument must be a number") cross = (other * self.vector_normal).unitVector() #this gives us a vector pointing in the right direction with a length of one result = cross * math.sin(angle) result += (other.unitVector() * math.cos(angle)) result = result.unitVector() result = result * other.get_distance() return result
def __mul__(self,other): #This accepts Vector * Constant = Vector or Vector x Vector = Vector if is_num.isNumber(other): x = self.x * other y = self.y * other z = self.z * other return Vector(x,y,z) elif isinstance(other,Vector): #here we do the cross product, notably NOT the dot product #if I need that I will make a dot product function x = (self.y*other.getZ() - self.z*other.getY()) y = (self.z*other.getX() - self.x*other.getZ()) z = (self.x*other.getY() - self.y*other.getX()) return Vector(x,y,z) else: raise IncorrectMultiplication("You must multiply a Vector by a Constant or Vector")
def rotate(self,other,angle): #this rotates an vector around the vector normal to the plane #returns a vector if not isinstance(other,Vector): raise IncorrectInput("The first input must be a Vector") if not is_num.isNumber(angle): raise IncorrectInput("The second agrument must be a number") cross = (other * self.vector_normal).unitVector() #this gives us a vector pointing in the right direction with a length of one result = cross * math.sin(angle) result += (other.unitVector() * math.cos(angle)) result = result.unitVector() result = result * other.get_distance() return result
def __mul__(self, other): #This accepts Vector * Constant = Vector or Vector x Vector = Vector if is_num.isNumber(other): x = self.x * other y = self.y * other z = self.z * other return Vector(x, y, z) elif isinstance(other, Vector): #here we do the cross product, notably NOT the dot product #if I need that I will make a dot product function x = (self.y * other.getZ() - self.z * other.getY()) y = (self.z * other.getX() - self.x * other.getZ()) z = (self.x * other.getY() - self.y * other.getX()) return Vector(x, y, z) else: raise IncorrectMultiplication( "You must multiply a Vector by a Constant or Vector")
def __init__(self, body_one, body_two, barycenter, vector_normal, vector_inline, specific_orbital_energy, eccentricity): #sanitizing if isinstance(body_one, sphere.Sphere): self.body_one = body_one else: raise IncorrectInput("The first input must be a sphere") if isinstance(body_two, sphere.Sphere): self.body_two = body_two else: raise IncorrectInput("The second input must be a sphere") if isinstance(barycenter, coordinate.Coordinate): self.barycenter = barycenter * constants.AU #this module attemps to measure things in meters, but takes AU as input else: raise IncorrectInput("The third input must be a Coordinate") if isinstance(vector_normal, coordinate.Vector): self.vector_normal = vector_normal.unitVector() #I don't care about the length of a vector so it is standardized else: raise IncorrectInput("The fourth input must be a Vector") if isinstance(vector_inline, coordinate.Vector): self.vector_inline = vector_inline.unitVector() #this is a vector from the barycenter to the first focal point #the negative of this vector is from the barycenter to the second focal point #also this vector has no meaningfull magnitude so it is standardized else: raise IncorrectInput("The fifth input must be a Vector") if is_num.isNumber(specific_orbital_energy): self.specific_orbital_energy = float(specific_orbital_energy) #this is one of the more arbitrary parts of the whole system #it is possible to calculate the energy from a single position of the orbit #however I decided that was not the focus of the project and so it takes the energy as a number else: raise IncorrectInput("The sixth input must be a number") if self.specific_orbital_energy >= 0: raise IncorrectInput( "The inputs do not make a valid elliptical orbit.\nThe specific orbital energy must be less than 0" ) if is_num.isNumber(eccentricity): self.eccentricity = float(eccentricity) else: raise IncorrectInput("The seventh input must be a number") #some conviences self.mass_sum = body_one.mass + body_two.mass self.standard_gravitation_parameter = constants.G * self.mass_sum #This is mu self.reduced_mass = (self.body_one.mass * self.body_two.mass) / self.mass_sum self.mass_ratio_one = self.body_one.mass / self.mass_sum self.mass_ratio_two = self.body_two.mass / self.mass_sum self.semimajor_sum = -1 * self.standard_gravitation_parameter / ( 2 * self.specific_orbital_energy) self.semimajor_sum = self.semimajor_sum * constants.AU #this is a major calculation for the whole orbit self.semimajoraxis_one = self.semimajor_sum * self.mass_ratio_two self.semimajoraxis_two = self.semimajor_sum - self.semimajoraxis_one # self.angular_momentum = self.reduced_mass * math.sqrt( # constants.G * self.mass_sum * self.semimajor_sum * (1 - self.eccentricity **2)) #turns out I never used this so I didn't need it self.period = 2 * math.pi * math.sqrt( self.semimajor_sum**3 / self.standard_gravitation_parameter) #also a major calculation that give the answer in years distance_to_focal_one = 2 * self.semimajoraxis_one * self.eccentricity distance_to_focal_two = -2 * self.semimajoraxis_two * self.eccentricity #this one is negative becuase it is in the oppositve direction of the inline vector self.focal_one = self.barycenter + (self.vector_inline * distance_to_focal_one) self.focal_two = self.barycenter + (self.vector_inline * distance_to_focal_two) self.ellipse_one = ellipse.Ellipse(self.focal_one, self.barycenter, self.vector_normal, 2 * self.semimajoraxis_one) self.ellipse_two = ellipse.Ellipse(self.focal_two, self.barycenter, self.vector_normal, 2 * self.semimajoraxis_two)
def get_relative_speed(self,distance): #I never use this but I could to find out the speed at different points around the orbit if not is_num.isNumber(distance): raise IncorrectInput("The first argument must be a number") return math.sqrt(2 * (self.specific_orbital_energy + (self.standard_gravitation_parameter / distance)))
def __init__(self,body_one,body_two,barycenter,vector_normal,vector_inline,specific_orbital_energy,eccentricity): #sanitizing if isinstance(body_one,sphere.Sphere): self.body_one = body_one else: raise IncorrectInput("The first input must be a sphere") if isinstance(body_two,sphere.Sphere): self.body_two = body_two else: raise IncorrectInput("The second input must be a sphere") if isinstance(barycenter,coordinate.Coordinate): self.barycenter = barycenter*constants.AU #this module attemps to measure things in meters, but takes AU as input else: raise IncorrectInput("The third input must be a Coordinate") if isinstance(vector_normal,coordinate.Vector): self.vector_normal = vector_normal.unitVector() #I don't care about the length of a vector so it is standardized else: raise IncorrectInput("The fourth input must be a Vector") if isinstance(vector_inline,coordinate.Vector): self.vector_inline = vector_inline.unitVector() #this is a vector from the barycenter to the first focal point #the negative of this vector is from the barycenter to the second focal point #also this vector has no meaningfull magnitude so it is standardized else: raise IncorrectInput("The fifth input must be a Vector") if is_num.isNumber(specific_orbital_energy): self.specific_orbital_energy = float(specific_orbital_energy) #this is one of the more arbitrary parts of the whole system #it is possible to calculate the energy from a single position of the orbit #however I decided that was not the focus of the project and so it takes the energy as a number else: raise IncorrectInput("The sixth input must be a number") if self.specific_orbital_energy >= 0: raise IncorrectInput("The inputs do not make a valid elliptical orbit.\nThe specific orbital energy must be less than 0") if is_num.isNumber(eccentricity): self.eccentricity = float(eccentricity) else: raise IncorrectInput("The seventh input must be a number") #some conviences self.mass_sum = body_one.mass + body_two.mass self.standard_gravitation_parameter = constants.G * self.mass_sum #This is mu self.reduced_mass = (self.body_one.mass * self.body_two.mass)/self.mass_sum self.mass_ratio_one = self.body_one.mass / self.mass_sum self.mass_ratio_two = self.body_two.mass / self.mass_sum self.semimajor_sum = -1 * self.standard_gravitation_parameter / ( 2 * self.specific_orbital_energy) self.semimajor_sum = self.semimajor_sum * constants.AU #this is a major calculation for the whole orbit self.semimajoraxis_one = self.semimajor_sum * self.mass_ratio_two self.semimajoraxis_two = self.semimajor_sum - self.semimajoraxis_one # self.angular_momentum = self.reduced_mass * math.sqrt( # constants.G * self.mass_sum * self.semimajor_sum * (1 - self.eccentricity **2)) #turns out I never used this so I didn't need it self.period = 2 * math.pi * math.sqrt(self.semimajor_sum**3/self.standard_gravitation_parameter) #also a major calculation that give the answer in years distance_to_focal_one = 2 * self.semimajoraxis_one * self.eccentricity distance_to_focal_two = -2 * self.semimajoraxis_two * self.eccentricity #this one is negative becuase it is in the oppositve direction of the inline vector self.focal_one = self.barycenter + (self.vector_inline * distance_to_focal_one) self.focal_two = self.barycenter + (self.vector_inline * distance_to_focal_two) self.ellipse_one = ellipse.Ellipse(self.focal_one,self.barycenter,self.vector_normal,2*self.semimajoraxis_one) self.ellipse_two = ellipse.Ellipse(self.focal_two,self.barycenter,self.vector_normal,2*self.semimajoraxis_two)