Explanation of House Blueprint Example Trigonometry

I’m following along the the Babylon example https://doc.babylonjs.com/guidedLearning/workshop/House and am having the hardest time wrapping my head around the trigonometry expressed in the code. In the tutorial it only says

The position of each new corner is determined using trigonometry on half the angle formed at the corners.

Specifically, I’d love to understand trigonometry involved in computing the outer corners that come from extending the inner corners by ply.


Hi @nerdsrock and welcome to the community. Sorry for the delay I have been working on my understanding of a different problem.

To be honest it is not just trigonometry it is vectors as well.
Inner wall is red and outer wall is blue. The distance between the walls ply is h

At corner M joining the inner and outer walls cuts the angle in half. Once we know the angle a, the we can find w using tan(a) = h / w, so w = h / tan(a);

Knowing the inner corner point as a vector vec_p, at M, we find the outer corner point vec_o at M using vec_0 = vec_p + vec_w + vec_h

Since we know the prev corner point vec_c before M we can find the vector from M to the previous corner, vec_p - vec_c, this will lie along the red line from M. We can then find the unit vector along the line from M to the previous corner using normalize.

vec_i = (vec_p - vec_c).normalize()

and so vec_w = w * vec_i

since vec_h is perpendicular to vec_i which lies in the XZ plane, take vec_i = (x, 0, z) then vec_j = (z, 0, -x) is a unit vector perpendicular to vec_i

so vec_0 = w * vec_i + h * vec_j.

We still need to find the angle a. We can do this since we can find the unit vector from M to N vec_k and the dot product on the vectors gives the cosine of 2a

cos(2a) = dot(vec_i , vec_ k)

a = acos(dot(vec_i , vec_ k)) / 2;

Moving to corner N we note that the change in angle is anti-clockwise rather than clockwise as it is at M and this means that the vector vec_w perpendicular to the current vec_h is towards not away from the corner so requires a change in direction.

Since vec_i and vec_k at a corner lie in the XZ plane their cross product is along the y axis and its direction depends on whether the change in angle is clockwise or anticlockwise so at a corner cross(vec_i, vec_k) is +1 or -1

Using direction = cross(vec_i, vec_k) means we find the outer corner from

direction * w * vec_i + h * vec_j.


Kudos for the excellent explanation! Going to bookmark this one :heart_eyes_cat:

Hello @nerdsrock just checking in, was your question answered?

Yes, it was! Thanks for following up @carolhmj :smiley:

1 Like