SNOT road generator help


SNOT road generator help
#1
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]
}


Attached Files
.ldr   temp.ldr (Size: 1.21 KB / Downloads: 4)
Reply
Re: SNOT road generator help
#2
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?


Attached Files
.ldr   temp.ldr (Size: 1.21 KB / Downloads: 1)
Reply
Re: SNOT road generator help
#3
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.
Reply
Re: SNOT road generator help
#4
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.


Attached Files
.ldr   RAMP 04.ldr (Size: 120.79 KB / Downloads: 3)
Reply
Re: SNOT road generator help
#5
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.


Attached Files
.txt   create_road_spline.js.txt (Size: 3.14 KB / Downloads: 3)
Reply
Re: SNOT road generator help
#6
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
Reply
Re: SNOT road generator help
#7
Where might i find such a library?
Reply
Re: SNOT road generator help
#8
If I understand you correctly you are searching for:
http://msdn.microsoft.com/en-us/library/...85%29.aspx
or
http://msdn.microsoft.com/en-us/library/...85%29.aspx
or
http://stackoverflow.com/questions/45051...ix-thingxy

I hope this helps.

Edit:
Just found: http://glmatrix.net/ - this should be what you are looking for Smile
Reply
Re: SNOT road generator help
#9
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.


Attached Files
.ldr   temp.ldr (Size: 1.46 KB / Downloads: 1)
Reply
Re: SNOT road generator help
#10
Ok, but you know that your bricks overlap?
Reply
Re: SNOT road generator help
#11
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?


Attached Files
.ldr   RAMP 04.ldr (Size: 120.79 KB / Downloads: 2)
Reply
Re: SNOT road generator help
#12
Did you talk about this http://gallaghersart.com/page/custom_mod...sion_sp04g ?

Edit:
Oh, now i got the right row Smile

You are talking about this http://gallaghersart.com/images/made/ite...4_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.
Reply
Re: SNOT road generator help
#13
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/
Reply
Re: SNOT road generator help
#14
Good idea!!

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

Thanks!
Reply
Re: SNOT road generator help - Progress!! And problems.
#15
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!


Attached Files
.mpd   ldr_slope_generator_01.mpd (Size: 21.32 KB / Downloads: 3)
Reply
Re: SNOT road generator help - Progress!! And problems.
#16
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.


Attached Files
.mpd   curvedRoadTest.mpd (Size: 4.29 KB / Downloads: 1)
Reply
Re: SNOT road generator help - Progress!! And problems.
#17
The white bricks in your example are turned the wrong way. Thanks, though.
Reply
Re: SNOT road generator help - Progress!! And problems.
#18
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


Attached Files
.mpd   ldr_slope_generator_02.mpd (Size: 56.8 KB / Downloads: 1)
Reply
Re: SNOT road generator help
#19
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.
Reply
Re: SNOT road generator help
#20
Thanks for making me discover http://www.brickbending.com/ - very nice work!
Reply
Re: SNOT road generator help
#21
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
Reply
Re: SNOT road generator help - Done?
#22
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.


Attached Files
.txt   create_road_spline_v1_0_1.zip.txt (Size: 30.57 KB / Downloads: 1)
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 3 Guest(s)