In my app, the user is able to draw each wall from scratch, so he decides whether to start drawing clockwise or counter-clockwise.
I need to change the parallelLines function so that the parallel lines are always on the outside, no matter what direction the walls are drawn.
Because currently the function works for 1 direction only. In the example, you can see that even though I use the outerPoints, the lines are drawn in the inside side for the 3 tubes. Thats not what I want.
I hope this makes sense. Let me know if you need clarification.
Assuming that the walls are drawn first in the XZ plane and the parallel lines are added by code rather than the user then find the center C of the room created by the walls, for each corner of the room P find unit vector2, u, in the direction CP and then the angle u makes with the x axis for each u
angle = Math.acos(dot(u, (1, 0)).Math.sign(z))
if angles in order increase then order of corners is counter clockwise and if they decrease then order of corners is clockwise (just check this is correct way round)
If the order is wrong way round then use .reverse on array of corners
Form your paths in the order you want to get displacement
No it was me. I forgot that acos only returns values from 0 to PI and for the full circle you need values from -PI to PI. You need to take into account the quadrant the corner is in relative to the room center. In your case the axes are XZ and cos is negative when z is negative so it needs a multiplication by 1 when z is positive and -1 when z is negative. Math.sign(z) gives these values.