When constructing your roller coaster it may be useful to design individual pieces and then connect those pieces at endpoints. For instance, suppose you want to match the end of a semicircle of radius 3 going from the point $(3,0,0)$ to the point $(0,0,3)$ described by the vector valued function $\mathbf{r}_1(t) = \langle 3\cos(t), 0, 3\sin(t) \rangle \qquad 0 \leq t \leq \frac{\pi}{2}$ with a straight line segment of length 4. We repesent the straight line segment using $\mathbf{r}_2(t) = \langle t, 0, 0 \rangle \qquad 0 \leq t \leq 4.$
Let's begin by examining a picture of our two pieces
var('t') # declare a variable r1 = vector([3*cos(t),0,3*sin(t)]) # define our first vector valued function r2 = vector([t,0,0]) # define the 2nd vector valued function above plot1 = parametric_plot3d(r1, (t,0,pi/2), color='red', thickness=5) plot2 = parametric_plot3d(r2, (t,0,4), color='green', thickness=5) show(plot1+plot2) # show the plot together
The above does not quite match up in the way we desire. To move the green straight line segment to the end of the semicircle, we need to shift the starting point over from $\mathbf{r}_2(0)= \langle 0,0,0 \rangle$ to $\mathbf{r}_1(0) = \langle 3,0,0 \rangle$. This can be done easily by adding the a vector representing the change from $\langle 0,0,0 \rangle$ to $\langle 3,0,0 \rangle$. This results in a change in $\mathbf{r}_2$ to $\mathbf{r}_2(t) + \langle 3,0,0 \rangle.$ Observe how this changes our picture.
r2 = r2 + vector([3,0,0]) # shift over r2 plot2 = parametric_plot3d(r2, (t,0,4), color='green', thickness=5) show(plot1+plot2) # show the plot together
Saying $\mathbf{r}_2 = \mathbf{r}_2 + \langle 3, 0, 0 \rangle$ does not make much sense mathematically. But, this is common practice in computer science, so one needs to understand the meaning. When $=$ is used in computing sciene, the typical interpretation is to take the right-hand-side and assign the value to the variable on the left-hand-side. In this particular instance, the right-hand-side is the "old" $\mathbf{r}_2$ given by $\langle t,0,0 \rangle$ added to the vector $\langle 3,0,0 \rangle$ to produce the new function $\langle t+3, 0,0 \rangle$. This function is now assigned to the variable $\mathbf{r}_2$ and from here on $\mathbf{r}_2$ with represent the vector valued function $\langle t+3, 0,0 \rangle$ (unless it is changed again).
To find the length of the roller coaster we make use of the standard formula for arc length. Recall the distance traveled by an object on a path $\mathbf{r}$ as $t$ goes from $a$ to $b$ is given by $\int_a^b \Vert \mathbf{r}'(t) \Vert \, dt.$ In the above example we use the above equation on each piece of the curve. The following sage commands are helpful
diff - used to take the derivative of a function
norm - used to find the magnitude of a vector
numerical_integral - used to perform a definite integral and get a decimal answer.
# we find the length of the red and green parts of the above picture # numerical integral returns two numbers, the integral approximation and the popential error r1_length = numerical_integral(norm(diff(r1,t)),0,pi/2) r2_length = numerical_integral(norm(diff(r2,t)),0,4) print "The length the red curve is", r1_length, "and the green curve is", r2_length # we only need the first number in the tuples total_length = r1_length[0] + r2_length[0] print "The total length is", total_length
Our path is currently 8.71 units. Suppose we would like to lengthen the path to be exactly 100 units. Since we are using vector valued functions this can be achieved easily. This is due to the fact that a vectors can be scaled to any length by multiplying then by an appropriate constant. Here out path is currently about 8.71 units and we wish it to be 100 units. Therefore, we multiply by the scalar $c = 100/8.71.$ Thus, the vector valued functions given by $c\mathbf{r}_1 \qquad \text{and} \qquad c\mathbf{r}_2$ should have the desired length.
Observe the following
# redefine our function c = 100/total_length r1 = c*r1 r2 = c*r2 # recreate the plots plot1 = parametric_plot3d(r1, (t,0,pi/2), color='red', thickness=5) plot2 = parametric_plot3d(r2, (t,0,4), color='green', thickness=5) show(plot1+plot2) # show the plot together # make sure the new length is 100 as we desire r1_length = numerical_integral(norm(diff(r1,t)),0,pi/2) r2_length = numerical_integral(norm(diff(r2,t)),0,4) # we only need the first number in the tuples total_length = r1_length[0] + r2_length[0] print "The total length is", total_length
Unfortunately, scaling the vectors has caused them not to meet up at the endpoints as we desire. Luckily, we already know how to fix this.