LDraw.org Discussion Forums
SNOT road generator help - Printable Version

+- LDraw.org Discussion Forums (https://forums.ldraw.org)
+-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html)
+--- Forum: LDraw Editors and Viewers (https://forums.ldraw.org/forum-11.html)
+--- Thread: SNOT road generator help (/thread-10517.html)



SNOT road generator help - Michael Horvath - 2013-11-01

I'm writing a script to generate SNOT roads but I have encountered a problem. As you can see the bricks in the attached file follow a neat curve. However the rotation of the parts around the z-axis is backwards. How do I fix this in the bricks' rotation matrices? Here's the relevant bit of code in the script I wrote:

Code:
var fTime = 1/2
while (fTime <= 1)
{
    var thisCoo = tCoordinates(fTime)
    var thisDiv = tDerivatives(fTime)
    thisDiv = vnormalize(thisDiv)
    sOutString += '1 16 ' + thisCoo[0] + ' ' + thisCoo[1] + ' 0 ' + thisDiv[0] + ' ' + thisDiv[1] + ' 0 ' + (-thisDiv[1]) + ' ' + thisDiv[0] + ' 0 0 0 1 3004.dat\n'
    fTime = bGetStuff(fTime, fTime + steps_distance_big, steps_distance_big, 1)[0]
}



Re: SNOT road generator help - Michael Horvath - 2013-11-01

OK, I got the curve working.

Code:
var fTime = 1/2
while (fTime <= 1)
{
    var thisCoo = tCoordinates(fTime)
    var thisDiv = tDerivatives(fTime)
    thisDiv = vnormalize(thisDiv)
    sOutString += '1 16 ' + thisCoo[0] + ' ' + thisCoo[1] + ' 0 ' + thisDiv[0] + ' ' + (-thisDiv[1]) + ' 0 ' + thisDiv[1] + ' ' + thisDiv[0] + ' 0 0 0 1 3004.dat\n'
    fTime = bGetStuff(fTime, fTime + steps_distance_big, steps_distance_big, 1)
}

Now how do I flip the bricks on their sides instead of standing up?


Re: SNOT road generator help - Roland Melkert - 2013-11-01

I don't know which language/library you are using. But it's probably much easier to use general rotation matrix manipulation functions instead of playing around with a single (normal) vector.


Re: SNOT road generator help - Michael Horvath - 2013-11-01

I'm using JavaScript. The derivatives correspond to the tangent lines, not the normals. Once normalized into a unit vector, they plug right in to the transformation matrix without needing extra effort to convert between degrees, radians, sines, cosines, etc.

The only part I don't get is how to also flip the bricks on their sides so the studs face outward.

In the attachment you can see the appearance I'm aiming for.


Re: SNOT road generator help - Michael Horvath - 2013-11-01

I've attached the script in its entirety to this post. Simply rename it to "create_road_spline.js". On Windows you should be able to double click the file like a regular application and it will automatically generate a new LDRaw model.


Re: SNOT road generator help - Roland Melkert - 2013-11-01

You have to also rotate the bricks around their x-axis, when using rotation matrix tools this is simply done before the other tilting stuff using e.g.

matrix.rotate(0.5*M_PI, 1, 0, 0); //90deg rotate

And the tilt would go like e.g

matrix.rotate(tiltAngle, 0, 0, 1);

These are examples the syntax depends on the library used.

The tangent method might be faster (less overhead) but like you are experiencing it becomes very messy very soon Smile


Re: SNOT road generator help - Michael Horvath - 2013-11-02

Where might i find such a library?


Re: SNOT road generator help - Michael Heidemann - 2013-11-02

If I understand you correctly you are searching for:
http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.directx.matrix%28v=vs.85%29.aspx
or
http://msdn.microsoft.com/en-us/library/windows/desktop/bb281696%28v=vs.85%29.aspx
or
http://stackoverflow.com/questions/4505196/javascript-is-there-a-data-structure-matrix-thingxy

I hope this helps.

Edit:
Just found: http://glmatrix.net/ - this should be what you are looking for Smile


Re: SNOT road generator help - Michael Horvath - 2013-11-03

I don't mind doing a little matrix calculation.

But what do I do in this case? Simply multiply the first rotation matrix by the second?

[edit]

I got it working! Yes, the matrices need to be multiplied. See the attachment.


Re: SNOT road generator help - Michael Heidemann - 2013-11-03

Ok, but you know that your bricks overlap?


Re: SNOT road generator help - Michael Horvath - 2013-11-03

The overlap is not so bad if you turn on seam width. I'm not sure though how Mike Gallagher was able to construct the curvy roads here:

http://gallaghersart.com/page/misc_custom_lego_roads (row 3 in the gallery)

Also, I could try building it this way instead:

http://www.flickr.com/photos/12333864@N05/3646860002

What do you think?


Re: SNOT road generator help - Michael Heidemann - 2013-11-03

Did you talk about this http://gallaghersart.com/page/custom_modular_snot_roads_version_sp04g ?

Edit:
Oh, now i got the right row Smile

You are talking about this http://gallaghersart.com/images/made/item/1400/1400_1120_83/GallaghersArt_ramp_04_a_sm.jpg.
You need to know the maximum angle that can the parts can be turned in this case. Then you are really close for the solution.


Re: SNOT road generator help - Tim Gould - 2013-11-03

This website shows some pretty small circles. Which should give you an idea of the maximum change of angle allowed by real 1x2 bricks.

http://www.brickbending.com/


Re: SNOT road generator help - Michael Horvath - 2013-11-04

Good idea!!

I sent him an email asking what the maximum angle between two bricks is.

Thanks!


Re: SNOT road generator help - Progress!! And problems. - Michael Horvath - 2013-11-04

As you can see in the attachment several problems remain.

1. The slope bricks are a tad bit higher than the surrounding road pieces.
2. The ends of the slope road don't line up properly with the adjacent streets. At best there will be a gap between each section.
3. Connecting the road surface to the sidewalks might not be possible. Meaning that they will need to be supported from beneath by pillars or something.
4. If you look very closely, the rows of alternating white bricks are a bit off center and do not correct properly with each other.

Enjoy!


Re: SNOT road generator help - Progress!! And problems. - Roland Melkert - 2013-11-04

I realized this is basically a bezier curve, so I went and play a bit with my LDCad path generator (which uses bezier curves).

While it uncovered a minor bug, I did manage to set the attached model up.

Maybe you could use it to generate the complete road. All you have to do is change the segment submodel. If the length of the segment changes you also need to adjust the segmentlength parameter of the path skin (it's set to 48 now so it ignores the top studs)

The mentioned bug is update related so you might need to manually force a regen (F5) or just restart the app after changes to be sure the correct segment version is used.

This is because I never actually tested using a submodel for a donor Smile

Anyhow I thought this might be useful.


Re: SNOT road generator help - Progress!! And problems. - Michael Horvath - 2013-11-04

The white bricks in your example are turned the wrong way. Thanks, though.


Re: SNOT road generator help - Progress!! And problems. - Michael Horvath - 2013-11-05

This is about as perfect as I am going to get. There still is a gap at the end of the road between it and the next road. I think that is unavoidable unless there are some "magic numbers" where all the math works out and the pieces line up.


Mike


Re: SNOT road generator help - Michael Horvath - 2013-11-05

I got an email back from the creator of http://www.brickbending.com/. He said the maximum bending angle for 1x2 bricks is between 6 and 7.5 degrees.

Jeff Wrote:If you don want to push the limits of the bricks, you can safely get a 6 degree angle between two bricks in a bend (i.e. a 60 brick circle doesn't put too much stress on the bricks). I tend push the limits in my designs, so when a circle is called for I'll typically use 48 bricks (7.5 degree angles).

I'll have to dig through my Lego in storage to see what I can come up with.


Re: SNOT road generator help - Philippe Hurbain - 2013-11-05

Thanks for making me discover http://www.brickbending.com/ - very nice work!


Re: SNOT road generator help - Michael Horvath - 2013-11-05

OK, I tried to create a ring of 60 real 1x2 bricks but wasn't able to get the two ends to connect to each other to form a circle. In the process I also broke two bricks.

Sad


Re: SNOT road generator help - Done? - Michael Horvath - 2013-11-06

Here's the script in its entirety. I added a warning when the angle between two bricks is greater than 6 degrees, as per Jeff at the Brick Bending website.

The script runs from the command line on windows. I included a batch file with the proper settings. Though you'll have to edit the paths to get it to work on your computer.

[edit]

Oops. I forgot to include all the needed files in the attachment. Please re-download.