[Home]History of UtilityClass

Robo Home | Changes | Preferences | AllPages


Revision 16 . . (edit) March 11, 2006 15:45 EST by AvihooI
Revision 14 . . March 11, 2006 15:20 EST by AvihooI
Revision 11 . . (edit) October 26, 2005 2:30 EST by Voidious [minor question answered]
  

Difference (from prior major revision) (minor diff, author diff)

Added: 28a29,33
Read what I had to say up there for Angles.
Distance is basically pythagoras theorem (a^2+b^2=c^2)
you do something like this: Math.sqrt(dX*dX+dY*Y).
-- AvihooI


Added: 41a47,153

Here's a Vector2D class that I wrote, feel free to use it (AvihooI):

/*For this class, sin and cos are inversed because robocode requires it
*Also, the angles are in Radians */

public class Vector2D
{
double x,y; //Vector coordinates

//Cartesian Representation
public double getX()
{
return x;
}

public double getY()
{
return y;
}

public void setX(double sX)
{
x = sX;
}

public void setY(double sY)
{
y = sY;
}

//Polar representation
public double getMagnitude()
{
return Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
}

public double getDirection()
{
return Math.atan2(x,y);
}

public void setMagnitude(double sMagnitude)
{
double theta = getDirection();
x = sMagnitude * Math.sin(theta);
y = sMagnitude * Math.cos(theta);
}

public void setDirection(double sDirection)
{
double magnitude = getMagnitude();
x = magnitude * Math.sin(sDirection);
y = magnitude * Math.cos(sDirection);
}

//Vectorial manipulations

public Vector2D Normalise()
{
double theta = getDirection();
return new Vector2D(Math.sin(theta), Math.cos(theta));
}

public Vector2D Add(Vector2D sVector2D)
{
return new Vector2D(x + sVector2D.x, y + sVector2D.y);
}

public Vector2D Substract(Vector2D sVector2D)
{
return new Vector2D( x- sVector2D.x, y - sVector2D.y);
}

public Vector2D Inverse()
{
return new Vector2D(-x,-y);
}

public double Dot(Vector2D sVector2D)
{
return Math.sqrt(x * sVector2D.x + y * sVector2D.y);
}

public Vector2D Multiply(double sScalar)
{
return new Vector2D(x * sScalar, y * sScalar);
}

public Vector2D(double sX, double sY)
{
x = sX;
y = sY;
}

public Point2D.Double translateToPoint()
{
return new Point2D.Double(x,y);
}

public Point2D.Double translateToPoint(Point2D.Double source)
{
return new Point2D.Double(source.x + x, source.y + y);
}

}


Robo Home | Changes | Preferences | AllPages
Search: