javascriptmathmql

Get the angle of two cross line


I want to get the angle of crosspoint of line A and B.

LineA = a1(100.0,100.3) to a2(100.1,100.2)
LineB = b1(100.0,100.1) to b2(100.1,100.4)

This Line A and Line B are crossed.

But how can I get the angle of cross point??

double a1x = 100.0;
double a1y = 100.3;
double a2x = 100.1;
double a2y = 100.2;
double b1x = 100.0;
double b1y = 100.1;
double b2x = 100.1;
double b2y = 100.4;

It is general programming question.

Not necessary the answer to the specific language.

I can use tanToRadian() method to calculate radian, so get tangent is OK.

and use Math.sqrt() to square the number.

Please give me a hint.


Solution

  • Just apply its formula:

    const ma = (100.2 - 100.3)/(100.1 - 100.0)
    const mb = (100.4 - 100.1)/(100.1 - 100.0)
    
    const tgx = Math.abs((ma - mb)/(1 + ma*mb));
    
    const resp = tanToRadian(tgx);
    

    (Not tested once you did not provide tanToRadian() func