![](https://static.wixstatic.com/media/5d91a3_d9d39b8b6fc34d8bbdfee6f7bd0860a2~mv2.png/v1/fill/w_980,h_368,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/5d91a3_d9d39b8b6fc34d8bbdfee6f7bd0860a2~mv2.png)
I have been working on fixing bugs and rework the sidewalk since the last post. The main issue I was trying to fix is the mesh of the sidewalk will overlap itself if the the width of the sidewalk is too wide.
![](https://static.wixstatic.com/media/5d91a3_bcbd46361c77487da918d58a1ef0654f~mv2.png/v1/fill/w_941,h_566,al_c,q_90,enc_auto/5d91a3_bcbd46361c77487da918d58a1ef0654f~mv2.png)
The way I generate the sidewalk before was extruding the road edge out along the point normal. However, It happened because I was using the subdivided edge and there are too many points at the corner. They are going to pass through each other as they extrude out.
![](https://static.wixstatic.com/media/5d91a3_2c778460e70347129158b4cda346445d~mv2.png/v1/fill/w_980,h_506,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/5d91a3_2c778460e70347129158b4cda346445d~mv2.png)
To fix this issue, I am using the none subdivided version of the edge, so there's only one point at each corner. I also separated the road edges into fill and expand groups. Fill the edges that are closed, and expand out the edge if it's not. Thus, I can have faces I can possibly use for generating buildings, and also avoid small edges extrude and overlap because the width is too high.
![](https://static.wixstatic.com/media/5d91a3_4991fa8e40db448a8718a82b423ef0d1~mv2.png/v1/fill/w_974,h_699,al_c,q_90,enc_auto/5d91a3_4991fa8e40db448a8718a82b423ef0d1~mv2.png)
![](https://static.wixstatic.com/media/5d91a3_178efc5f513e449db8ef5746751d0375~mv2.png/v1/fill/w_975,h_697,al_c,q_90,enc_auto/5d91a3_178efc5f513e449db8ef5746751d0375~mv2.png)
For the expanding edges, I transfer normals from the subdivided edge to get a more accurate normal angle. However, there is an issue with this method because the magnitude of the normal is all the same.
![](https://static.wixstatic.com/media/5d91a3_9b0efdb6f7b941d9af2ca46c141c6a8b~mv2.png/v1/fill/w_971,h_493,al_c,q_90,enc_auto/5d91a3_9b0efdb6f7b941d9af2ca46c141c6a8b~mv2.png)
Edges will not extrude out evenly because the normal is at an angle instead of perpendicular to the edge. As the image shown below, the point is not actually moving out the same distance in the perpendicular directions as other points that the Normal is at 90 degree angle. In order to make the edge extrudes evenly, I have make the magnitude of the normal bigger.
![](https://static.wixstatic.com/media/5d91a3_cabe7e2d0053425f9692a8a7642d6318~mv2.png/v1/fill/w_958,h_501,al_c,q_90,enc_auto/5d91a3_cabe7e2d0053425f9692a8a7642d6318~mv2.png)
![](https://static.wixstatic.com/media/5d91a3_267eb175ce64435eb7bc510c175fb8cf~mv2.png/v1/fill/w_980,h_804,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/5d91a3_267eb175ce64435eb7bc510c175fb8cf~mv2.png)
To solve this, I used measure node to calculate the curvature of each points in oder to make changes to the corner points. After that, I calculate the normal by finding the average direction vector by adding directional vector pointing toward the previous and the next point.
![](https://static.wixstatic.com/media/5d91a3_df0b596be4c54fd085df1d3d30e4530a~mv2.png/v1/fill/w_980,h_748,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/5d91a3_df0b596be4c54fd085df1d3d30e4530a~mv2.png)
![](https://static.wixstatic.com/media/5d91a3_fdff5bb914a4429c8d98cffd214732f8~mv2.png/v1/fill/w_980,h_370,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/5d91a3_fdff5bb914a4429c8d98cffd214732f8~mv2.png)
The result is working very well with some exceptions. The new normal is an average direction from the points before and after which means it is pointing toward the middle of those points. It will point in the opposite direction when the edge is turning the opposite way than the normal.
![](https://static.wixstatic.com/media/5d91a3_71fb5555a3fd4bfda73d87142e1f9f9e~mv2.png/v1/fill/w_842,h_468,al_c,q_90,enc_auto/5d91a3_71fb5555a3fd4bfda73d87142e1f9f9e~mv2.png)
The issue was resolved by using the dot product to compare the new normal with the old transferred normal. The dot product will return a positive value if the two vector directions are less than 180 degrees apart and return a negative value if its more than 180 degrees. Therefore, I can flip the normal if it's going in the opposite direction from the transferred normal since the direction of the old normal is correct.
![](https://static.wixstatic.com/media/5d91a3_637357fd1d0b4d34811ffb3d75adbeef~mv2.png/v1/fill/w_980,h_367,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/5d91a3_637357fd1d0b4d34811ffb3d75adbeef~mv2.png)
After solving these issues, the sidewalk is working nicely no matter the width of the sidewalk the user chose, and I can start working on adding randomize buildings next.
Here is a quick breakdown of how the city generator is working right now.
Comments