Answered step by step
Verified Expert Solution
Question
1 Approved Answer
18.5 Celestial Bodies A simulation of the solar system would contain many different celestial bodies such as stars, planets, or moons. We want to
18.5 Celestial Bodies A simulation of the solar system would contain many different celestial bodies such as stars, planets, or moons. We want to approach the problem of keeping track of these bodies through an object-oriented approach where each body is represented by an instance of class of the type of body. In this problem you will create a base class CelestialBody and derive classes for Planet and Moon from the base class. You will then create instances for planet Earth (a Planet) and its moon Luna (a Moon) and planet Mars (Planet) and its moons Deimos (Moon) and Phobos (Moon). Base class CelestialBody Create a class CelestialBody. It should have the following attributes, which are all initialized with mandatory arguments in the order below when a new instance is created: .name: name of the body position: a numpy array with the three cartesian coordinates in the coordinate system that has the center of mass of the solar system at its origin (solar barycentric"), in astronomic units (AU) mass: mass of the body in kg . radius: approximate radius in km The class should have the following methods: volume(): return the volume of the body (calculated as a sphere from the radius) density(): return the mass density (mass divided by volume) of the body . . delta_r(other): The method takes another Celestial Body (or Planet or Moon) instance as an argument. It calculates and returns the cartesian difference vector (as a numpy array) pointing from itself to the other body. If the position of the body is r = (x, y, z) and the position of the other body is '= (x,y,z) then the difference vector is Ar-r' - r. distance (other): Like delta_r(), the method takes another CelestialBody instance as an argument and returns the distance between the two bodies as a float, . d = Ar. Ar. where the inner product (scalar product or "dot product") between two vectors is used. Derived classes The class Planet should be derived from CelestialBody. Nothing else is required. (Hint: You can always add a pass into the body of the new class definition.) The class Moon should be derived from Celestial Body. It should be initialized with name, position, mass, radius, and the new argument parent.parent should be the planet, represented by a Planet, around which the moon orbits. Moon should have an attribute parent that stores the parent planet. Celestial objects Create the following objects (all data were obtained from the NASA HORIZON system): earth = Planet ("Earth", luna = Moon ("Luna", np. array ([9.978977040419635E-01, 6.586825681892025E-02, -6.320430920521123E-06]), 5.97219e24, 6371.01) name np. array ([9.956768547953816E-01, 6.676030485840675E-02, 1.641093070596718E-04]), 7.349 22, Also create mars and its moons deimos and phobos based on the following table (the radii for the moons are estimates because their actual shape is far from spherical). Note that Mars (as a Planet) does not have a parent so the entry in that column of the table was left empty. 1737.53, earth) Z radius parent "Mars" -1.638989837611019E+00 2.909235766064876E-01 4.607875056151672E-02 6.4171e23 3389.92 "Deimos" -1.638943766241257E+00 2.907775944863155E-01 4.60446557052641 4E-02 1.80e20 29 "Phobos" -1.638995094538730E+00 2.909862261134459E-01 4.608601582090829E-02 1.08e20 24 luna.name Testing The tests test the objects and their methods. For example, the following should work: Name of the Earth's moon: X Distance between Luna and its parent, Earth: luna.distance (luna.parent) Direction from Earth to Mars: earth.delta_r (mars) Density of Phobos and Deimos phobos.density() deimos. density () (Note: we did not do customary unit conversion so the density is in kg/km.) mass mars mars imports and class definitions here if _name__ == "_main__": create your objects here earth Planet ("Earth", np.array([9.978977048419635E-01, 6.586825681892025E-02, -6.320430920521123E-06]), 5.97219024, 6371.01) luna Moon ("Luna", np.array([9.956768547953816E-01, 6.676030485840675E-02, 1.641093070596718E-04]), 7.349e22, 1737.53, earth) # add mars, phobos, delmos here #testing print(luna.name) print(luna.distance(luna.parent)) print(earth.delta_r(nars)) print (phobos.density()) print(deinos.density())
Step by Step Solution
There are 3 Steps involved in it
Step: 1
import numpy as np class CelestialBody def initself name position mass radius selfname name selfposi...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started