简体   繁体   English

三角形中的矩形

[英]Rectangle in a triangle

I am trying to build a program in C++ that will procedurally generate cities. 我正在尝试用C ++构建一个程序生成城市的程序。 For the moment, the city is represented by an array of blocks either Quad blocks or Triangle blocks. 目前,城市由四个块或三角块组成的块阵列表示。

I can't find an effective way to subdivide a triangle (TBlock) into a rectangle (QBlock) and three triangles. 我找不到将三角形(TBlock)细分为矩形(QBlock)和三个三角形的有效方法。

在此输入图像描述

So picture a triangle ABC. 所以想象一个三角形ABC。 We have two point T and T' which are the first and second tier of line segment BC. 我们有两个点T和T',它们是BC线段的第一和第二层。 Now I need to find P and P' which are respectively on AB and AC line segments. 现在我需要找到分别在AB和AC线段上的P和P'。 P is the intersection of AB and the normal of BC passing through T. P' is the intersection of AB and the normal of BC passing through T'. P是AB与通过T的BC的法线的交点.P'是AB与通过T'的BC的法线的交点。

I know how to find T and T' and the inward normal of vector BC but I can't find a way to compute the normal passing through T or T'. 我知道如何找到T和T'以及矢量BC的向内法线但是我找不到计算通过T或T'的法线的方法。

Thanks ! 谢谢 !

Given your (BC) vector is (x, y), a normal vector of BC is (-y, x). 给定(BC)向量是(x,y),BC的法向量是(-y,x)。 Now offset the normal vector by coordinates of T', and you will get the normal of BC passing through T'. 现在通过坐标T'偏移法向量,你将得到通过T'的BC的法线。

the normal to a line y = m*x + c is the line y = (-1/m)*x + d , where c and d are constants. 线y = m*x + c的法线是线y = (-1/m)*x + d ,其中cd是常数。 You have two lines with a common point (T or T'), you can solve simultaneously to find m and d for both T and T'. 你有两条带有公共点(T或T')的线,你可以同时解决以找到T和T'的md

You know that the angle formed by CBA is the same angle formed by TBP. 你知道CBA形成的角度与TBP形成的角度相同。 Let's call that O. You also know the distance between B and T. Call it D. Using this we can find P using trigonometry. 我们称之为O.你也知道B和T之间的距离。称之为D.使用这个我们可以使用三角法找到P.

Tan(O) = X / D Tan(O)= X / D.

Where X is the y_axis distance between T and P. Just solve for X since you know O and D. 其中X是T和P之间的y_axis距离。因为你知道O和D,所以只需求解X.

Once you know X you can just add X to the y value of T to find P. 一旦你知道了X,你就可以将X加到T的y值来找到P.

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

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