Instead of typing it all out, here's a picture for you to see what I want. You know what they say, a picture is worth a thousand words.
What I have is p1
, Θ
, and d
and speed, s
of the projectile.
Speed:
From this I can deduce p2
using the equation p1.x * speed
, p1.y * speed
which are the co-ordenates for p2
. From this I can calculate the distance using the equation |dx| + |dy|
.
Distance
However, if I wasn't given speed, how would I be able to calculate the co-ordenates of p2
only using Θ
, p1
and d
?
Are there any other methods that would be the most efficent?
public double getDistanceTraveled() {
return Math.abs(x - oldX) + Math.abs(y - oldY);
} //use Manhattan aproach as it is more efficent than Euclidean
public double getSpeed() {
return getDistanceTraveled() / level.TICKS_PER_SECOND;
}
is what I am using at the moment. I realized that I had the variable time, so I was able to deduce p2
using this method:
d = |dx| + |dy|
d = s / t
s = t(|dx| + |dy|)
Not sure if this is that efficient though. Any suggestions to this problem, and just to repeat: I have the variables theta
, p1
, d
and t
and I have to find p2
.
Efficency >>> Accuracy