0
$\begingroup$

I'm am trying to figure out how to calculate an expected x y position given starting x y, velocity and angle. If velocity is a maximum of 4 pixels per turn how can i estimate where finishing position is in say 5 turns time?? I'd really appreciate a formula for this as I've been trying to implement it in code but I'm clearly not very good with math. Much thanks in advance kind people

$\endgroup$
2
  • $\begingroup$ You are allowed a maximum of four pixels per "turn", does this mean you could always use the maximum, or that you have to consider what the minimum might do as well? $\endgroup$
    – abiessu
    Feb 28, 2015 at 4:04
  • $\begingroup$ sorry yes the minimum is 1 $\endgroup$
    – kfcobrien
    Feb 28, 2015 at 4:17

1 Answer 1

1
$\begingroup$

Break it into coordinate directions. Given an angle of $\theta$ where an angle of zero corresponds to the positive $x$ direction, and an angle of $90^\circ$ (or equivalently $\pi/2$ radians) corresponds to the positive $y$ direction, an initial $x$ coordinate (labeled here as $x_i$), an initial $y$ coordinate (labeled here as $y_i$), and an initial velocity (labeled here as $v$) you have the parametric equations:

$$x(t) = x_i + vt\cos(\theta)\\y(t)=y_i+vt\sin(\theta)$$

It should be mentioned, here I use $v\cos(\theta)$, but you could just as easily define $v_x = v\cos(\theta)$ where $v_x$ is the "velocity in the $x$ direction." This simplifies equations in the case that you don't want or need to find or define the exact angle.

Since you say "pixels" you might need to plan ahead or round somehow in order to account for how far specifically in any direction the objects will go, either by displaying at the closest pixel (rounding), or specifically using velocities and angles that give integer value distances for the target resolution (specifically 3 pixels right and 1 pixel up for example).

The equation becomes only slightly more complicated as you take acceleration into account. See any elementary physics book or the internet for a full list such as PhysicsClassroom.com

$\endgroup$
2
  • $\begingroup$ Also, consider the "fast line algorithm" for a decent integer-based approximation of any given angle $\endgroup$
    – abiessu
    Feb 28, 2015 at 4:02
  • $\begingroup$ Thank you mate, I think it may be my rounding problem that is why I'm unable to get it exact as I've been trying to use your solution all day. Thanks a million, I know I'm on the right track now and should hopefully get to the end of it shortly :) $\endgroup$
    – kfcobrien
    Feb 28, 2015 at 4:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .