How to infer the possible values for the final two coordinates of a trapezoid when all 4 line lengths are known

你说的曾经没有我的故事 提交于 2021-01-28 09:09:39

问题


I have a trapezoid where I know the length of all 4 lines, and I know the coordinates of two of the corners. How do I find the coordinates of the remaining two corners in JavaScript?

NOTE: All 4 lines are of different length, ie this is not an isosceles trapezoid

Here's a little diagram in case it helps:

       L3  
    D ____ C
     /    \
 L4 /      \ L2 
    --------
  A    L1    B

I know the coordinates of A and B, and the length of L1, L2, L3, and L4 (Which are all different). I just need to get all of the possible sets of coordinates for D and C!


回答1:


Drop vertical lines from points C and D to the line AB to find their projections on E and F on AB:

Now AED and BFC are right triangles with the same height. Let's call the height h. From Pythagoras:

a² + h² = L4²     and     b² + h² = L2²

Subtracting one equation from the other you get: a² - b² = L4² - L2²

Also you can divide L1 into segments AE, EF, and FB, so the length of L1 must be:

L1 = a + L3 + b    =>    a + b = L1 - L3

Therefore we have a system of equations in a and b:

a² - b² = L4² - L2²
a + b  = L3 - L1

Using the fact that a² - b² = (a+b)(a-b) and the above equation, you get:

(L3 - L1)(a - b) = L4² - L2²   =>   a - b = (L4² - L2²)/(L3 - L1)

(Note that L1 and L3 can not be equal. If L1 = L3, there is an infinite number of solutions.)

So the equations simplify to:

a + b  = L3 - L1
a - b = (L4² - L2²)/(L3 - L1)

The solution is:

a = (L3 - L1 + (L4² - L2²)/(L3 - L1)) / 2
b = (L3 - L1 - (L4² - L2²)/(L3 - L1)) / 2

The height of the trapezoid is:

h = sqrt(L4² - a²) = sqrt(L2² - b²)

You could now use a to solve for the angle at point A and b to solve the angle at point B, and use them to calculate the coordinates for C and D. Or you can use a, b, and h directly.

For example: suppose A is at the origin (0,0) and B is at (L1, 0). Then the two solutions are:

  • C is at (a, h) and D is at (L1 - b, h)
  • C is at (a, -h) and D is at (L1 - b, -h)


来源:https://stackoverflow.com/questions/61140525/how-to-infer-the-possible-values-for-the-final-two-coordinates-of-a-trapezoid-wh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!