/*
 * HorizontalLine.java
 *
 * Created on 22 grudzień 2004, 00:20
 */

package JSciDraw.physics.forces.constraints;

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

/**
 *
 * @author  Barbara 
 */
public class GeneralLine extends Constraints{
    
    /** Creates a new instance of HorizontalLine */
    public GeneralLine(double slope) {
      params=new double[1];
      params[0]=-slope;
    }
    
    public void draw(ClassicalParticleV2D p, java.awt.Graphics2D g2D) {
      if (draw){ 
       double xP=p.getPosition().getComponent(0);
       double yP=p.getPosition().getComponent(1);
       double b=(yP-(params[0]*xP));
       g2D.setColor(Color.black);
       g2D.drawLine(0,(int)b,800,(int)((800*params[0])+b));
      }
    }
    public void erase(ClassicalParticleV2D p, java.awt.Graphics2D g2D) {
      if (draw){
       double xP=p.xOl;
       double yP=p.yOl;
       double b=(yP-(params[0]*xP));
       g2D.setColor(Color.white);
       g2D.drawLine(0,(int)b,800,(int)((800*params[0])+b));
      }  
    }
    
    public void move(ClassicalParticleV2D p, AbstractDoubleVector force, double dt)
    {
     AbstractDoubleVector fc;
     fc=getTangent(new Double2Vector()).scalarMultiply(force.scalarProduct(getTangent(new Double2Vector())));
     fc=fc.scalarMultiply(dt/(p.getMass()));
     p.setVelocity((p.getVelocity()).add(fc));
     p.setPosition(p.getPosition().add((p.getVelocity()).scalarMultiply(dt)));
    }

    public AbstractDoubleVector getTangent(AbstractDoubleVector x0) {
        AbstractDoubleVector b=new Double2Vector(1,params[0]);
        b.normalize();
        return b;
    }
    
    public AbstractDoubleVector toEuclidean(AbstractDoubleVector generic) {
        return generic;
    }
    
    public AbstractDoubleVector toGeneric(AbstractDoubleVector euclidean) {
        return euclidean;
    }
     public void setPosition(AbstractDoubleVector x) {
    }
   
     public AbstractDoubleVector getPosition() {
         return new Double2Vector(0,0);
     }
     
}
