package physics;

import math.matrix.Vector;
import stdlib.StdDraw;

/**
 * 2D Body with a position, velocity and mass.
 * @author Daniel Weschke
 */
public class Body {
    private Vector r;      // position
    private Vector v;      // velocity
    private double mass;   // mass

    public Body(Vector r, Vector v, double mass) {
        this.r = r;
        this.v = v;
        this.mass = mass;
    }

    public void move(Vector f, double dt) {
        Vector a = f.times(1/mass);
        v = v.plus(a.times(dt));
        r = r.plus(v.times(dt));
    }

    public Vector forceFrom(Body b) {
        Body a = this;
        double G = 6.67e-11;
        Vector delta = b.r.minus(a.r);
        double dist = delta.norm();
        double F = (G * a.mass * b.mass) / (dist * dist);
        return delta.direction().times(F);
    }

    public void draw() {
    	StdDraw sd = new StdDraw();
        sd.setPenRadius(0.025);
        sd.point(r.get(0), r.get(1));
    }

	public static void main(String[] args) {
		Body body = new Body(new Vector(0,1),new Vector(1,0),1);
		body.draw();
	}
} 
