I am trying to understand the math equations from https://doc.babylonjs.com/snippets/house
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 )
JohnK
July 9, 2019, 3:26pm
3
% 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.
JohnK
July 24, 2019, 2:53pm
5
previousWall = (CurrentWall - 1) % nbWalls
In mathematics, modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value—the modulus (plural moduli). The modern approach to modular arithmetic was developed by Carl Friedrich Gauss in his book Disquisitiones Arithmeticae, published in 1801.
A familiar use of modular arithmetic is in the 12-hour clock, in which the day is divided into two 12-hour periods. If the time is 7:00 now, then 8 hours later it will be 3:00. Usual addition would ...