Jump to content

[SOLVED] Tangent to Spline?


photo

Recommended Posts

Posted

Hello,

I'm trying to draw the tangent vectors along a WorldSpline (2.19) (The world spline is at world origin, with no rotation.)

auto pos = path->segment->calcPoint(t);
auto dir = path->segment->calcTangent(t);
Visualizer::renderDirection(pos, dir, vec4_blue, 0.25f, true, 0, false);

But this tangent is not tangent at all... Am I doing something wrong?

 

Posted

Here the dark blue line should be tangent to the light blue spline (tangent = should be along the flow of the spline 'river')

image.png.ac08c85c1b7fefcc3c6f51bbbb279b66.png

 

 

Posted

Hi Stephane,

Could you please share a small sample to help us reproduce the issue?

So far with that code:

Vector<SplineSegmentPtr> segments;
wsg_->getSplineSegments(segments);
for (const auto &segment : segments)
{
	const float step = 1.0f / 32.0f;
	for (int i = 0; i < 32; ++i)
	{
		float t = step * i;
		auto pos = segment->calcPoint(t);
		auto dir = segment->calcTangent(t);
		Unigine::Visualizer::renderDirection(pos, dir, vec4_blue, 0.25f, true, 0, false);
	}
}

The results looks pretty much correct(?):

image.png

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

Soooo apparently the real code was a bit less trivial and my excerpt was incomplete here. It appears the worldsplinegraph wsg was not, in fact, at world origin with a zero rotation, and the code tried to compensate incorrectly. For future reference, as this may help others:

auto wt = wsg->getWorldTransform();

// This was incorrect
pos = wt * path->segment->calcPoint(t);
dir = wt * path->segment->calcTangent(t); //< treats a direction as a position, BAD!

// This is correct
pos = wt * path->segment->calcPoint(t);
quat q = wt.getRotate();
dir = q * path->segment->calcTangent(t);

Treating a direction as a position is bad when doing matrix multiplication, duh...

  • Like 1
  • silent changed the title to [SOLVED] Tangent to Spline?
×
×
  • Create New...