问题描述
嘿,那里的人,我正在学习processing.js,并且遇到了一个数学问题,我无法用有限的几何和三角知识或者通过维基百科帮助解决这个问题。
我需要绘制一个矩形。要绘制这个矩形,我需要知道每个角的坐标点。我所知道的是盒子顶部和底部中点的x和y以及所有四条边的长度。
无法保证盒子的方向。
有什么帮助?这似乎应该很容易,但它真的让我感到困惑。
如果这个四边形是一个矩形(所有四个角都是90度),那么它可以被解决。 (如果它可能是任何四边形,那么它是不可解的)如果点是(x1,y1)和(x2,y2),并且如果两个点不是完美的垂直(x1 = x2)或水平(y1 = y2),那么矩形的一条边的斜率是
m1 =(y2-y1)/(x2-x1)
和另一个的斜率边缘是:
m2 = - 1 / m1
如果知道两侧的长度和两个相对侧的中点,则可以通过将dx,dy添加到中点来轻松确定更正点:(如果L是长度中等价位的边)
pre $ code> dx = Sqrt(L ^ 2 /(1 + m2 ^ 2))/ 2
和
Hey there guys, I'm learning processing.js, and I've come across a mathematical problem, which I can't seem to solve with my limited geometry and trigonometry knowledge or by help of Wikipedia.
I need to draw a rectangle. To draw this rectangle, I need to know the coordinate points of each corner. All I know is x and y for the midpoints of the top and bottom of the box, and the length of all four sides.
There is no guarantee on the orientation of the box.
Any help? This seems like it should be easy, but it is really stumping me.
解决方案If this quadrilateral is a rectangle (all four angles are 90 degrees), then it can be solved. (if it could be any quadrilateral, then it is not solvable)
if the points are (x1,y1), and (x2, y2), and if the two points are not perfectly vertical (x1 = x2) or horizontal (y1 = y2), then the slope of one edge of the rectangle is
m1 = (y2-y1) / (x2-x1)
and the slope of the other edge is:
m2 = - 1 / m1
If you know the lengths of the sides, and the midpoints of two opposite sides, then the corrner points are easily determined by adding dx, dy to the midpoints: (if L is length of the sides that the midpoints are on)
dx = Sqrt( L^2 / (1 + m2^2) ) / 2
and
dy = m2 * dx
NOTE: if the points are vertically or horizontally aligned, this technique will not work, although the obvious solution for those degenerative cases is much simpler.
这篇关于知道一个矩形的两个点,我怎么能找出其他两个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!