Calculate vector from two points and angle

163 Views Asked by At

I have three points:

     P1 (5065, 423)
     P2 (4935, 281)
     P3 (0, 0)

enter image description here

I calculated the angle between P3,P2 and P2,P1, as result I got: 3.878736

Now I would like to test my result, by construction the vector P3,P2 with my calculated angel and the points P1and P2

Next i would check if the point P3 (0,0) is located on the constructed vector:

How can I get a vector from this 3 factors? Thanks

enter image description here



The angle I calculated with this formula and code:

MY.math = {
    angle: function(p1, p2, p3){
        if (p3){
            return Math.abs(MY.math.angle(p1, p3) - MY.math.angle(p2, p3));
        }

        var angle = Math.atan2(p2.y - p1.y, p2.x - p1.x);

        while (angle < 0){
            angle += 2 * Math.PI;
        }

        return angle;
    }
}
1

There are 1 best solutions below

0
On BEST ANSWER

I think you may use rotation of the vector $P_1P_2$ around the z- axis. Take $P_1=(5065,423,0)$, $P_2=( 4925,281,0)$, and consider the rotation matrix around the z-axis $$ Rot_z(\theta)=\begin{bmatrix} \cos(\theta) & -\sin(\theta) & 0 \\ \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 1 \end{bmatrix}$$ Where $\theta= 3.878736$. Then your vector $P_2P_3$ is $$ P_2P_3=Rot_z(\theta) P_2P_1 $$ You will get a $3$D vector whose last component is zero, taking the first two components you will get your $ P_2P_3$.

Hope this helps you.