Hey Im currently learning about geometry and vectors and was trying to build a room builder with three js.

I basicly create walls from two points (p1, p2). I draw a line and extrude the line to a rectangle. I create the rectangle by making a path of 4 points, where I offset the two points p1, p2 in the perpendicular direction (normal) of the line in both directions (right and left of the line). In code I used this pattern (Extrude = e)

e2 _______________e4

Now I noticed a weird but obvious behavior. When I draw the wall from p2 to p1 instead of p1 to p2 everything starts to rotate

e3 _______|_______e1

Now I wonder how to work around this behavior. I want to connect the walls to all other walls having the same points. So Im calculating the angle of all walls to get the two neighbours of the current wall, when I have multiple connections.

\ /

Here is the issue im facing. When I want to calculate the intersection point of a wall and its neighbours, therefore I use 2 extruded points of wall1 and two of wall2, but I dont know which sides of the wall are facing each other.

I guess the actual question is how to handle a positive and negative draw direction of a line and how to get the sides facing to each other.

Any help is highly appreciated Ask for more infos please


1 Answer 1


I can see 2 ways of attacking this.

  1. You could organize all the walls of the world into a tree data structure (or maybe a forest, if you have like a list of separate rooms). This way, you can arrange the wall data so p1 always comes before p2 when traversing the points to draw the walls.

  2. Use the natural ordering from the underlying coordinate system. Assuming you already have a 3D space, then you've got a straightforward way to sort the points of a line.


You could use this ordering to sort the points of a line and always draw it in a consistent orientation.

Re-reading the question, I may not have fully understood what the problem is that you're facing. Hopefully this will at least spark some ideas.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.