Alright dishmoth, I think I got the grasp of it, I’d just like a few of my thoughts ironed out.
I understand that direction is a unit vector - and velocity is not since we keep adding the acceleration vector to it. Does this leave position to be a unit vector also? Since position doesn’t really have a magnitude (unless its the size of the image?).
I’m guessing I can test if it is a unit vector by simply printing out Math.sqrt(position.x * position.x + position.y * position.y). Is that what this formula is all about? giving the magnitude of a certain vector?
I’ve changed how the car class works to interact with a Vector2D class but I’m not totally sure that I’m doing things the right way. I’ll post a snippet of what I mean.
This is the mathematical vector class
public class Vector2D {
private double x;
private double y;
public Vector2D(double x, double y) {
this.x = x;
this.y = y;
}
public static Vector2D add(Vector2D v1, Vector2D v2) {
return new Vector2D(v1.x + v2.x, v1.y + v2.y);
}
public double getX() {
return x;
}
public double getY() {
return y;
}
}
and some implementation in my car’s movement method
...
direction = new Vector2D(Math.sin(Math.toRadians(carAngle)), -Math.cos(Math.toRadians(carAngle)));
velocity = new Vector2D(direction.getX() * currentSpeed * deltaSeconds, direction.getY() * currentSpeed * deltaSeconds);
position = Vector2D.add(velocity, position);
...
and I still don’t fully understand why everything except velocity can be considered a vector - instead of a Point? Or maybe a vector is just a Point with a direction? ahhh I’m so confused. The thing is I know once I can get the theory down the implementation would be no problem.
Oh and by the way, philfrei I understand what you mean, this was taken care of in another thread I posted asking about top down rotation motion
- thanks though!