First of all, I'm not sure whether to post this on stackoverflow or here, but since there's some mathematics needed here (especially at the end of this question) I posted it here.
I'm given a parametric curve $\mathbf{r}(t)$. The center of a road in 3d-space is that curve. I also want to be able to rotate the road about the tangent by some angle. (for example to tilt the road in curves, or to make corkscrews like in roller coasters).
I think there are two ways of specifying this angle:
- let $a(t)$ be the total rotation of the road. $a(t)=0$ corresponds to the road being normally oriented and $a(t)=180$ corresponds to the road being upside down.
- let $b(t)$ be the change of the angle at some point. If $b(t)>0$ the road rotates clockwise and if $b(t)<0$ the road rotates anti-clockwise.
I first implemented the former approach. I rotated the global upwards vector around the tangent vector at each point, took away the tangent component, normalized it and let the result be my local upwards vector at that point. Problems were vertical roads, since the resulting local upwards vector would be zero. Also there was a problem with loops since the global upwards angle "switched sides of the road" resulting in a sudden 180° rotation of the road at the vertical parts.
Then I tried the second approach. I iterated through the curve increasing $t$ by a fixed constant each time. Then I took the local upward vector from the previous value of $t$, rotated it around the new tangent, subtracted the tangent component and normalized it to get the new local upwards vector. Problems with this approach are that the result depends on the step size and that I need to start calculating from the beginning to get the local upwards vector at some point.
A new idea I had:
Define $\mathbf{u}(t)$ to be the local upwards vector and define $\mathbf{t}(t)$ to be the tangent vector at the point with parameter $t$. Also define $M$ to be a rotation matrix around $\mathbf{t}(t)$ by an angle $b(t)$. Let $\mathbf{u}(t+h)=M*(\mathbf{u}(t)-(\mathbf{u}(t) \cdot \mathbf{t}(t))*\mathbf{t}(t))$
Now I'd need to find $\mathbf{u}'(t)=\frac{\mathbf{u}(t+h)-\mathbf{u}(t)}{h}$ and then find $\mathbf{u}(t)$ and normalize it to get the local upwards vector at any point on the curve.
Questions:
- Is there something I missed with the first approaches that eliminates the problems?
- Is it possible to find $\mathbf{u}(t)$ using the last idea? If so, how would you do that?
- Do you have any other idea how to calculate the local coordinate system of these roads?
If $\mathbf r(t)$ is a nice enough curve (i.e. it's twice differentiable), I think the moving frame is probably the best way to handle all of this.
Also, I think this formula will be useful for you when you're trying to find that rotation matrix $M$, if you don't have a formula already.