Stable way to process spline cross section orientation

Started by
1 comment, last by JoeJ 6 years ago

Hey

I'm dealing with ribbons following the shape of multiple spline segments. It's straightforward to compute the direction at any point along the spline. However the ribbon also got a flat shape and I'm struggling with finding a way to compute the angle of the ribbon in the plane perpendicular to the direction.

To illustrate what I mean here's a piece of code that almost worked:


	float3x3 rotMtxFromSpline;
	rotMtxFromSpline[1] = normalize(splineDir);
	rotMtxFromSpline[0] = normalize(cross(float3(1, 0, 0), rotMtxFromSpline[1]));
	rotMtxFromSpline[2] = cross(rotMtxFromSpline[0], rotMtxFromSpline[1]);

	// Rotate rotMtxFromSpline[0] in the rotMtxFromSpline[0]-rotMtxFromSpline[2]-plane to align with float3(0, 0, 1) dir
	rotMtxFromSpline[0] = normalize(dot(rotMtxFromSpline[0], float3(0, 0, 1)) * rotMtxFromSpline[0] + dot(rotMtxFromSpline[2], float3(0, 0, 1)) * rotMtxFromSpline[2]);
	rotMtxFromSpline[2] = cross(rotMtxFromSpline[0], rotMtxFromSpline[1]);

The problem with this code is when the spline segment becomes perpendicular to (0,0,1)-dir as the orientation switch from one side to the other very easily.

The approach above is kind of a global approach and I'm thinking if there's a way to append some info to each spline segment to remedy the issue.

Anyhow I wanted to post this question in case anyone had a similar problem that they solved or maybe anyone know some web resource dealing with this issue?

 

Thanks!

Advertisement

The usual solution is probably to define orientations for each control point, with the local X axis aligned to the spline tangent directions.

In between you can first interpolate between those orientations (e.g. using quaternion slerp),

and second align the resulting orientation X axis to the current spline tangent as well (using axis and angle rotation from X axis to tangent).

This is robust, but requires some manual setup of the initial orientations at the control points because their angle around X is undefined. You can eventually automate this using an up vector if your usecase allows this. (problem: e.g. making a racing track from a single spline, the orientation on the top of a looping would need to point downwards nut upwards to avoid twisting.)

This topic is closed to new replies.

Advertisement