vardump
vardump

Reputation: 658

Two.JS Point on Curve

I have a Two.JS Polygon Object. Now I want the x/y position of a point (the point's position is given on the curve in %)

A Two.JS Polygon has the property ending. You can give a number between 0 and 1 there. Thats what I want for a particular point. Is there a way to get the x/y of a point ON the curve?

Maybe it's possible with another JS Canvas/SVG Lib.

Upvotes: 1

Views: 825

Answers (1)

Wolfgang Kuehn
Wolfgang Kuehn

Reputation: 12926

Sure. Suppose that vertices is your Two.Vector with which you construct the polygon, and pos is the position in %. Then you get the vertex and its position by

var i = round((pos * vertices.length)/100);
var v = vertices[i];
console.log(v.x, v.y);

Now this gives you a vertex, and pos is the relative index position.

If you want to have the point on the curve which lies exactly pos% of curve length away from the beginning, that's harder.

Upvotes: 1

Related Questions