[Back to Contents]

Tutorial - Basic


Introduction
Using Variables
Using Functions
Adding Banking
Wrap Up

Introduction
  To start with, let's have a look at the Formula window. From the main NoLimits Elementary window, click the menu Advanced then Formula Input. For now, let's ignore the top half of the window and focus on the areas Initialization and Formula.

  The Initialization part of the formula is where you can setup variables to use in your formula. For now, let's skip down to the next section and start with a very simple formula.

  The Formula is where the actual element will be created. This is where we tell Elementary how to get the shape we want. To start with, let's create a very simple formula and then explore how it works.

In the Formula section, enter the following formula:
X = T * 10
Y = 1
Z = 0

Now that we have a formula, we need to actually calculate it. To do this, from the Formula Input window's menu, click Formula then Plot or you can simply press Ctrl + P. If you need to move the formula window so you can see the main window, go ahead and do so, then have a look at your now created element. It should look something like this:

  See all those purple colored spheres? Those are what were created by the formula. What happens is that T is a reserved variable. That means that T actually contains a value. The value in T is set by the formula engine. When a formula is plotted, the formula is called several times. Each time T has a different value. This value is between 0 and 1. What the value is depends on how many Divisions there are, but for this tutorial I am not going to explain this relationship (see the Advanced Tutorial when you are ready).

  Each time the formula is called, we are setting a position for X, Y and Z. These values represent 1 position in 3D space. You can think of it as X is left or right, Y is up or down and Z is front or back.

  Since we are changing only the X value each time the formula is called, we create an element that simply goes in a straight line to the right. Notice how we use T * 10. And since T will be a value between 0 and 1, when the formula is started we have:
    T = 0, so we have 0 * 10 which equals 0.
The next time we might have:
    T = 0.5, so we have 0.5 * 10 which equals 5.
And the final time, we will have:
    T = 1, so we have 1 * 10 which equals 10.
This is how the element knows that it goes from 0 to 5 to 10 along the X position. Since the element starts at 0 and goes to 10, we know that we have an element in a straight line that is exactly 10 meters in length.

 

Using Variables
  Let's modify our example slightly so that we can easily change how long our straight segment element is.

  First, let's setup our variable. To do this, we will put a line into the Initialize section. Add this line:
length = 20

  Now we need to modify our formula to use our variable. Change the X calculation in the formula, so the whole formula should look like this:
X = T * length
Y = 1
Z = 0

  Now, Plot the formula again. Your element will still be a straight line, but you will notice that it is now 20 meters long.

  You can now change the value of the "length" variable and Plot the formula again to see your changes. As an example, you can change it to: length = 30 and you will get a segment that is 30 meters in length.

  And now let's use a variable that changes every time the formula is calculated. To do this, we will put our new variable in the Formula section. Add a new variable before the X, Y and Z lines so your formula looks like this:
myT = T * 2
X = T * length
Y = 1
Z = 0

  And of course, we need to add the variable into our actual calculations. So again, let's modify the X calculation to use our new variable. The formula will look like this:
myT = T * 2
X = myT * length
Y = 1
Z = 0

  Now if you Plot the formula, you will see we still have a straight line, but the "length" of the element has doubled. This is because we are doubling T by using our variable in our calculation we are going from 0 to 2 instead of 0 to 1.

 

Using Functions
  Probably the most common functions you will use in creating an element will be Sin and Cos. So let's create a bit more complex formula using both of these functions. To start off with, let's clear out our old formula. To do this, simply click on the New button at the top of the window, and then click Yes on the confirmation.

  Let's create a simple circle. First, I want to make it so that I can easily change the radius of the circle. So we will add a variable for the radius in the Initialization section, like this:
radius = 20

  Now down to the formula. We are going to create a simple circle. To create a circle we use the Sin and Cos functions. We will put the Sin function for the X position and the Cos function for the Z position. Take note of the bracket style used on functions! The formula looks like this:
X = Sin[ T * Pi * 2] * radius
Y = 1
Z = Cos[ T * Pi * 2] * radius

  Go ahead and Plot the formula. Your element should look like this:

  Again you can change the "radius" value to effect the size of your circle.

  This element doesn't do us much good, so let's modify it slightly so that the height of the element changes. To do this, we want to create a calculation for the Y position. A very simple calculation would be to simply raise the value of Y. So let's give that a try, the formula will look like this:
X = Sin[ T * Pi * 2] * radius
Y = 1 + T * 10
Z = Cos[ T * Pi * 2] * radius

  Plot the formula. Your element should now look like this:

  Now we're getting somewhere. Do you notice the Blue Arrow pointing at the track? This arrow indicates the direction of the element. This is the path the train will take into the element. Notice that it is at the bottom? That might be good if your train has some speed, but I'd like this element to go downwards. No problem, all we need to do is modify the Y position to start high and go down. Change your formula to this:
X = Sin[ T * Pi * 2] * radius
Y = 11 - T * 10
Z = Cos[ T * Pi * 2] * radius

  Now Plot the formula again. The Blue Arrow should now be up in the air, indicating that the train will descend through the element.

  How about we make the height of the circle into a variable? You should be familiar with how to do this by now. But if not, add a new line to the Initialization section so that it now looks like this:
radius = 20
height = 10

  Then, of course, we need to change the calculation for Y so that it uses our variable. Notice that I am using brackets for this calculation. In this case, they are not really needed, but they help visually separate out that part of the calculation. That part of the calculation is again only there for visual reasons. If we did just "height - T * height" that would work just as well, but the end height would be at 0 (zero). This would make the element look like it's in the ground in our editor. Keep in mind the Ground and all the Grid-Lines are only there for visual aid, they do not effect the element in any way. The formula looks like this:
X = Sin[ T * Pi * 2] * radius
Y = ( height + 1 ) - T * height
Z = Cos[ T * Pi * 2] * radius

  You can now simply modify the values of "radius" and "height" in the Initialization section, without changing the Formula section, and get different sized downward circles.

 

Adding Banking
  The next step is to add banking to our element. Of course, without knowing the exact speed of the train as it enters an element, it's impossible to get banking that is perfect for a specific track. But, the banking can be generalized, and then modified when the element is used for a specific track. To add banking, we will introduce the B variable into our formula. Unlike X, Y and Z the banking variable B is optional. Let's setup some very basic banking using the formula we started in the Using Functions section of the tutorial. We will simply add banking based on the position we are at. Like this:
X = Sin[ T * Pi * 2] * radius
Y = ( height + 1 ) - T * height
Z = Cos[ T * Pi * 2] * radius
B = T * Pi / 2

  Plot the formula and have a look. The banking will start at 0 degrees, and increase throughout the element where it reaches 90 degree banking at the exit. It should look like this:

  It is also possible to set the banking to be an exact amount throughout the element. Just remember that banking is in Radians not degrees. If you are unsure of what the radian value is for a degree, use the following formula:
radians = degrees * Pi / 180

;Example
radians = 45 * Pi / 180   ;Radian value for 45 degrees

 

Wrap Up
  At this point you should have a basic understanding of how a formula is calculated. You should be able to create and use your own variables inside your formula. You should have a basic understanding of how to use functions inside your formula. And last but not least, you should be able to add basic banking to your elements.

  This tutorial by no means covers everything NoLimits Elementary's Formula System is capable of doing. It is only intended to get you started. Once you have a good understanding of the basics, you should read the Advanced tutorial.