So I am creating a physics ski simulation as a project on my University and the task that I've been struggling with for a couple of hours is:
How fast is a Skier moving towards a still obstacle at particular time?. It's described in the literature as $\nabla r_{ab}$ where $r_{ab}$ is the distance between skier and an obstacle. A picture that may be helpful
I've tried multiplying velocity's $x$ and $y$ components by $cos$ of the angles between them and the vector pointing toward the obstacle but didn't get the result I need.
EDIT: The things I know about skier are: position $(a_x, a_y)$, velocity $(V_x, V_y)$, forces that he is exposed to. The thing I know about obstacle is it's position $(b_x, b_y)$
The cosine formula should work if you apply it to the actual velocity vector itself. As you found out, it does not work on the components of that vector.
Use
sqrt(vx*vx + vy*vy)to find the magnitude of the skier's velocity, and something likeatan2(vy, vx)to find the skier's direction.For the direction, you may need to swap the
vxandvy, change sign, or add a constant to the result, depending on exactly how you have set up the coordinate system and how your software environment definesatan2. The angle will probably be given in radians, which is fine since you just need to pass it tocos. Try a few examples, printing out the components and the calculated angle, until you get it right.Alternatively, you can evaluate $$ \frac d{dt} \sqrt{ (x - x_b)^2 + (y - y_b)^2 } $$ given the skier's position $(x,y)$ and velocity components $(v_x, v_y)$, taking $\frac d{dt} x = v_x$ and $\frac d{dt} y = v_y$. But I do it the first way when I program something like this.