here’s my vector class
public class Vector2D {
public float X = 0.0f, Y = 0.0f;
public Vector2D() {}
public Vector2D( float x, float y ) { X = x; Y = y; }
public Vector2D( Vector2D a ) { X = a.X; Y = a.Y; }
public float length() {
return (float) Math.sqrt( (X * X) + (Y * Y) );
}
public Vector2D normalize(){
float len = length();
if (len > 0f || len < 0f) {
X /= len;
Y /= len;
}
return new Vector2D(X, Y);
}
public float dotProduct( Vector2D A, Vector2D B) {
return (A.X * B.X) + (A.Y * B.Y);
}
public Vector2D add( Vector2D a ) {
X += a.X;
Y += a.Y;
return new Vector2D(X, Y);
}
public Vector2D sub( Vector2D a ) {
X -= a.X;
Y -= a.Y;
return new Vector2D(X, Y);
}
public Vector2D mul( Vector2D a ) {
X *= a.X;
Y *= a.Y;
return new Vector2D(X, Y);
}
public Vector2D mul( float scalar ) {
X *= scalar;
Y *= scalar;
return new Vector2D(X, Y);
}
}
But how do you turn a line into a vector if you only know it’s two end points?
edit:
I found this:
[quote]In order to write down the vector equation of this line, we need to know two things.
* We have to know the position vector of some point which lies on the line, like a on my diagram.
* We have to know a vector which gives the direction of the line, like b in my diagram. This is called a direction vector.
Then the position vector r of any general point P on the line is given by the equation
r = a + tb
[/quote]
but to be honest… I don’t really understand how to program the “direction vector” thing?
Edit #2: Now I’m REALLLY confused. For a direction vector you need degrees?
http://www.analyzemath.com/vector_calculators/magnitude_direction.html
so do I need a direction vector, or just a vector, or the vector equation of a line(consisting of both)?
edit # 3: Wait so a vectors direction is derived from the line it makes from the origin 0,0?