gradientspace / geometry3Sharp

C# library for 2D/3D geometric computation, mesh algorithms, and so on. Boost license.
http://www.gradientspace.com
Boost Software License 1.0
1.71k stars 387 forks source link

TubeGenerator and arbitrary segment lengths #176

Open X-Celcius opened 2 years ago

X-Celcius commented 2 years ago

The TubeGenerator class currently uses CurveUtils.GetTangent to calculate the frame / plane when generating the ring vertex orientation along the path vertices. This works fine for paths that follow a uniform pattern and have almost equal segment lengths such as a ring. It leads to ugly results if one segment is followed by a much longer segment, however.

The following image shows a tube generated from 4 vertices. The fourth one is way of the screen and leeds to a tangent that has almost the same angle as the bottom tube segment: MicrosoftTeams-image (1)

If an additional vertex is added (the green one) the result looks much better: MicrosoftTeams-image

In case this is intended behavior that's fine, as it is fairly easy to add artificial segments to style the tube the way you want to. However in case this is unintended it would be nice to turn this behavior on or off and modify the code so that it calculates the tangent based on the actual angle of the turn without taking the length relation into account.

Example vertex coordinates:

( 20, 30, 0)
(  5, 30, 0)
(  5, 15, 0)
( 20, 15, 0) <- artificially added redundant vertex
(380, 15, 0) <- artificially added redundant vertex
(395, 15, 0)
(395, 30, 0)
(380, 30, 0)

A related second issue: You may notice in the screenshots that the diameter of the tube changes during these turns. I have yet to find out what in the code exactly causes this.