Sg2.9
Angle of a path at a certain...
Recent RSS
Angle of a path at a certain length
From:  Chris Deutsch
Date:  19. February 2010, 17:27

Is there a way to determine the angle of a path at a certain length of that path? Not of a certain point, mind you. If you have 2 points with different angles, the path between those points will have different angles all through the path, depending on the points' angles, yes, but not equal to them.

Thanks!

Re: Angle of a path at a certain length
From:  Jürg Lehni
Date:  19. February 2010, 18:17

Yes, there is.

You will need to work with the path.curves representation of a path as opposed to the path.segments.

The Curve object has a function called curve.getTangent(parameter) which returns the tangent in any given point of the curve as a point / vector. The position is defined by the bezier curve parameter that is a value between 0 and 1.

To find the curve / parameter pair at a given length of a path you can use path.getPositionWithLength(length) which returns a HitResult object that points to the curve and the bezier parameter at the given position. You then can use this to find the tangent in that point, and from this the angle. So to get the angle of the path at a third of its length, you would do this:

var pos = path.getPositionWithLength(path.length / 3);
var tangent = pos.curve.getTangent(pos.parameter);
var angle = tangent.angle;

That should do it!

Re: Angle of a path at a certain length
From:  Jürg Lehni
Date:  19. February 2010, 18:27

Thinking about this a bit more, I think it would actually be a good idea to expose getPoint, getTangent, getNormal in Path directly, with a length parameter instead of a bezier curve parameter, so Path.getPositionWithLength(length) would get called behind the scenes.

Re: Angle of a path at a certain length
From:  Chris Deutsch
Date:  20. February 2010, 20:56

Thanks! That should help me a lot :)

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Triangular 25.01.11