Question: Modify Body (Program 3.4.1) so that the radius of the circle it draws for a body is proportional to its mass. Program 3.4.1 Gravitational body

Modify Body (Program 3.4.1) so that the radius of the circle it draws for a body is proportional to its mass.

Program 3.4.1 Gravitational body public class Body { py private Vector r;

Program 3.4.1 Gravitational body public class Body { py private Vector r; private Vector v; private final double mass; public Body (Vector r0, Vector v0, double m0) { r = r0; v = v0; mass = m0; } public void move (Vector force, double dt) { // Update position and velocity. Vector a = force.scale(1/mass); v = v.plus (a.scale(dt)); r = r.plus (v.scale(dt)); } public Vector forceFrom(Body b) { // Compute force on this body from b. b } public void draw() { force dt G delta dist magnitude Body a this; double G = 6.67e-11; Vector delta = b.r.minus(a.r); double distdelta.magnitude(); double magnitude= (Ga.mass * b.mass) / (dist dist); Vector force = delta.direction ().scale (magnitude); return force; StdDraw.setPenRadius (0.0125); StdDraw.point (r.cartesian (0), r.cartesian (1)); position velocity V mass mass force on this body time increment acceleration this body another body gravitational constant vector from b to a distance from b to a magnitude of force

Step by Step Solution

3.49 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To modify the given Body class so that the radius of the circle it draws is proportional to its mass ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithm Design Questions!