/*
 * RigidLineV2D.java
 *
 * Created on 22 grudzień 2004, 00:17
 */

package JSciDraw.physics;

import JSci.physics.ClassicalParticle2D;
import JSci.maths.*;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Line2D;
import java.awt.geom.Area;
import java.awt.geom.AffineTransform;
import java.awt.Shape;
import JSci.physics.Force;
//import JSciDraw.Drawable;
import java.awt.Color;
import java.util.*;
/**
 *
 * @author  arturo
 */
public class DrawableRigidLineV2D extends DrawableRigidBodyV2D {

    double length;
    private AbstractDoubleVector constraint;
    /** Creates a new instance of DrawableRigidCircle */
    public DrawableRigidLineV2D(AbstractDoubleVector c) { 
        constraint = c;
    }
    public void setLength(double l) {
        area = new Rectangle2D.Double(0,-1,l,2);
        length = l;
    }
    public void calculateForces(double dt) {
        Iterator i  = forces.iterator();
        AbstractDoubleVector totalForce = new Double2Vector(0,0);
        while(i.hasNext()) {
            totalForce = totalForce.add( ((Force)i.next()).getVector(dt) );
        }
        Double2Vector tangent = new Double2Vector(
                (constraint.subtract(this.x)).getComponent(1),
                (constraint.subtract(this.x)).getComponent(0)
                );
        tangent.normalize();
        totalForce=tangent.scalarMultiply(totalForce.norm()*Math.cos(this.ang)/(this.getMomentOfInertia() ));
        this.applyForce( totalForce,x,dt );
    }
}
