Math in "Developing Build a House from a Floorplan"

I am trying to understand the math equations from Developing Build a House from a Floorplan - Babylon.js Documentation

Then the base for wall w, consists of corners numbered, w, (w + 1) % nbWalls, w + nbWalls, (w + 1) % nbWalls + nbWalls. See Fig 2.

If we assume that:

  • wall w = wall 3
  • nbWalls = 6

Then it means that the rest of the corners can be found as

  • w = corner 3 ?
  • (w + 1) % nbWalls = corner 4 ?
  • w + nbWalls = corner 9 ?
  • (w + 1) % nbWalls + nbWalls = corner 10 ???

If so, can someone give me a numerical example for caluclating (w + 1) % nbWalls ?

Pinging the author (@JohnK)

% is the modulo operator.

a % b ___ a and b integers, is the remainder when a is divided by b. Its use is sometimes called clock arithmetic. A clock at 12 returns to 12 every 12 hours so 12 + 12 = 12. 12 acts as 0

Take a building with 4 walls and so 4 corners. Wall 0 connects corners 0 to 1
Wall 1 - 1 to 2
Wall 2 - 2 to 3
Wall 3 - 3 to 0

In general corner i to corner i + 1 but this falls down when i = 3

Working modulo 4
(0 + 1) % 4 = 1
(1 + 1) % 4 = 2
(2 + 1) % 4 = 3
(3 + 1) % 4 = 0

If number of walls is nbWalls then for w = 0 to nbWalls - 1
Wall w join corner w to corner (w + 1) % nbWalls

2 Likes

@JohnK Can I use a similar equation to find the previous wall number?

Lets say we have a room with 4 walls (wall 0 - 3). THe previous wall of wall-0 is wall-3.

I suppose a refactored equation of the following would work?

(previousWall + 1) % nbWalls = CurrentWall

What is the equation to get previousWall? I dont know how to refactor it with the modulus.

previousWall = (CurrentWall - 1) % nbWalls