/*
 * Circle.java
 *
 * Created on 22 grudzień 2004, 12:00
 */

package JSciDraw.physics.forces.constraints;

import JSci.maths.*;
import JSci.physics.*;
import JSciDraw.*;
import JSciDraw.physics.*;
import JSciDraw.physics.forces.*;
import java.awt.*;
import java.util.*;

/**
 *
 * @author  Barbara 
 */
public class MoveableCircle extends Circle{
    
    protected ClassicalParticleV2D part;
    protected AbstractDoubleVector extForce;
    /** Creates a new instance of Circle */
    public MoveableCircle(double radius, ClassicalParticleV2D p,boolean drawJoint)
    {
      super(radius, p.getPosition());
      part=p;
      part.setHidden(!drawJoint);
    }
    
    public void draw(ClassicalParticleV2D p, java.awt.Graphics2D g2D) {
      if (draw){
       double x0=center.getComponent(0)-params[0];
       double y0=center.getComponent(1)-params[0];
       g2D.setColor(Color.black);
       g2D.drawOval((int)x0,(int)y0,(int)(2*params[0]),(int)(2*params[0]));
      }
      part.draw2D(g2D);
    }
    public void erase(ClassicalParticleV2D p, java.awt.Graphics2D g2D) {
      if (draw){ 
       double x0=part.xOl-params[0];
       double y0=part.yOl-params[0];
       g2D.setColor(Color.white);
       g2D.drawOval((int)x0,(int)y0,(int)(2*params[0]),(int)(2*params[0]));
      }
      part.erase2D(g2D);
    }
    
    protected void calcForce()
    {
      extForce=part.getForce();
    }
    
    public void move(ClassicalParticleV2D p, AbstractDoubleVector force, double dt)
    {
      part.calculateForces(dt);
      calcForce();
      AbstractDoubleVector sum=force.add(extForce.scalarMultiply(-1.*p.getMass()/part.getMass()));
      super.move(p,sum,dt);
      part.move2D(dt);
      center=part.getPosition();
      p.setPosition(p.getPosition().add(part.getPosition().subtract(new Double2Vector(part.xOl,part.yOl))));
    }
    
    public AbstractDoubleVector getTangent(AbstractDoubleVector x0) {
      return getAngularVersor(toGeneric(x0));
    }
    
   public double getRadius(double ang) {
      return params[0];
   }

}
