<p>I can see 2 ways of attacking this.</p>
<ol>
<li><p>You could organize all the walls of the world into a <em>tree</em> data structure (or maybe a <em>forest</em>, 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.</p>
</li>
<li><p>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.</p>
<p>(ax,ay,az,bx,by,bz)=&gt;ax&lt;bx?-1:ax&gt;bx?1:ay&lt;by?-1:ay&gt;by?1:az&lt;bz?-1:az&gt;bz?1:0</p>
</li>
</ol>
<p>You could use this ordering to sort the points of a line and always draw it in a consistent orientation.</p>
<p>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.</p>

CC BY-SA 4.0
2022-01-01T02:14:07.850Z
2022-01-01T02:14:07.850Z
luser droog
<p>Hey Im currently learning about geometry and vectors and was trying to build a room builder with three js.</p>
<p>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)</p>
<pre><code>e2 _______________e4
p1|______________|p2
e1|______________|e3
          |
</code></pre>
<p>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</p>
<pre><code>e3 _______|_______e1
p2|______________|p1
e4|______________|e2
</code></pre>
<p>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.</p>
<pre><code>\ /
 |
</code></pre>
<p>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.</p>
<p>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.</p>
<p>Any help is highly appreciated
Ask for more infos please</p>

<mesh><geometry>
Extrude from line and find intersection points
Fluqz
# Extrude from line and find intersection points

(Asked by: username_0 on 2021-12-29)

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
p1|______________|p2
e1|______________|e3
          |

```

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
p2|______________|p1
e4|______________|e2

```

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

**Tags:** mesh, geometry


---

## 1 answers

### Answer by username_1 on 2022-01-01. Score: 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.

   (ax,ay,az,bx,by,bz)=>ax<bx?-1:ax>bx?1:ay<by?-1:ay>by?1:az<bz?-1:az>bz?1:0

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.


---

