简体   繁体   English

所以我有一个三角形,点(100,90)距离(11)和线的角度(45°)我可以找到该线的另一个点吗? 怎么样?

[英]So I have a triangle with the point (100, 90) the distance (11) and the angle of the line (45º) Can I find the other point of the line? How?

okay so I am trying to draw a triangle, the triangle can be completely random, on a canvas in JavaScript 好吧所以我试图画一个三角形,三角形可以完全随机,在JavaScript的画布上

so I got the angles and the side for triangle ABC(this is not what I'm calling it in the code) 所以我得到三角形ABC的角度和侧面(这不是我在代码中称之为的)

the sides 双方

AB(11)
AC(12)
BC(13)

the angles which are solved in a function 在函数中求解的角度

BAC(69)
ABC(52)
BCA(59)

And the starting Point of the triangle at (100, 90) 和(100,90)三角形的起点

The question I am having is how do I find the other points to the Triangle I thought the easiest way to draw it would be to draw a line that goes to each point 我遇到的问题是如何找到三角形的其他点我认为绘制它的最简单方法是画一条线到每个点

So I tired the mathematics with this code (I found on another page but ) 所以我用这段代码累了数学(我发现在另一页但是)

function FindTriPoints(){
//Y2 = H(Sin(A)) + Y1
//X2 = Sqrt((H^2)-(Y2^2)) + X1
pointX1 = 100;
pointY1 = 90;

pointY2 = s3 * (Math.sin(angle1*Math.PI/180)) + pointY1;
pointX2 = Math.sqrt((s3 * s3) - (pointY2 * pointY2)) + pointX1;

alert("X2 = " + pointX2 + "\n Y2 = " + pointY2)
}

but X2 ends up becoming NaN because it is a negative value that it is trying to square root. 但是X2最终成为NaN,因为它是一个负值,它试图平方根。

Edit Thanks to Cbroe and Jing3142 for helping me with Y2 编辑感谢Cbroe和Jing3142帮助我Y2

well if you know valid triangle sides lengths (l1,l2,l3) and their angles (a,b,c) ... 好吧,如果你知道有效的三角形边长(l1,l2,l3)和它们的角度(a,b,c)......

  • then it is quite simple with vector math ... 那么矢量数学很简单......

三角形

// compute directions
a1=0;
a2=180-b;
a3=a2+180-c;
a3=-b-c;
a3=-a;
// convert them from [deg] to [rad]
a1*=Math.pi/180.0;
a2*=Math.pi/180.0;
a3*=Math.pi/180.0;
// compute points
A=(x0,y0); // your start point is known
B=A+l1*dir(a0)=(x0+l1*Math.cos(a0),y0+l1*Math.sin(a0));
B=A+l1*dir( 0)=(x0+l1               ,y0                 );     // a0 is always zero
C=A-l3*dir(a3)=(x0-l3*Math.cos(a3),y0-l3*Math.sin(a3));    // C from A point
C=B+l2*dir(a2)=(x0+l1+l2*Math.cos(a2),y0+l2*Math.sin(a2)); // C from B point

[notes] [笔记]

  • as you can see there are more alternatives for some variables choose one you like 你可以看到有更多的选择一些变量选择一个你喜欢的
  • do not forget to check if l1+l2>l3 and l1+l3>l2 and l2+l3>l1 别忘了检查l1 + l2> l3和l1 + l3> l2和l2 + l3> l1
  • if not then your lengths are not valid triangle sides 如果没有那么你的长度不是有效的三角形边
  • also a+b+c = 180 也是a + b + c = 180
  • if not then your angle computation is wrong 如果没有那么你的角度计算是错误的
  • if you want to over-check the triangle then compute C from A and from B point 如果要过度检查三角形,则从AB点计算C.
  • if they are not the same (their distance > some accuracy constant like 0.001) 如果它们不相同(它们的距离>某些精度常数如0.001)
  • then it is not a valid triangle 那么它不是一个有效的三角形

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM