# LDraw.org Discussion Forums

Full Version: SNOT road generator help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
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 + ' ' + thisCoo + ' 0 ' + thisDiv + ' ' + thisDiv + ' 0 ' + (-thisDiv) + ' ' + thisDiv + ' 0 0 0 1 3004.dat\n'     fTime = bGetStuff(fTime, fTime + steps_distance_big, steps_distance_big, 1) }```
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 + ' ' + thisCoo + ' 0 ' + thisDiv + ' ' + (-thisDiv) + ' 0 ' + thisDiv + ' ' + thisDiv + ' 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?
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.
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.
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.
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 Where might i find such a library?
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 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?

I got it working! Yes, the matrices need to be multiplied. See the attachment.
Ok, but you know that your bricks overlap?
Pages: 1 2 3