javascript - How to find the coordinates value of all the points which divides the line into 5 equal parts -


how divide line n equal parts, eg- 5 equal parts.

for example need add 5 points on straight line based on starting , ending point xy co-ordinates given below: starting point :

x1 : 0.27176220806794055 y2 : 0.7258064516129032 

ending point

x1 : 0.6303191489361702 y2 : 0.348993288590604 

how find coordinates value of points divides line 5 equal parts.

divide distance between start , end points 5 each component separately, , use compute interior points:

function divideintofivesegments(startpoint, endpoint) {     let {x: x1, y: y1} = startpoint;     let {x: x2, y: y2} = endpoint;      let dx = (x2 - x1) / 5;      let dy = (y2 - y1) / 5;      let interiorpoints = [];      (let = 1; < 5; i++)         interiorpoints.push({x: x1 + i*dx, y: y1 + i*dy});      return [startpoint, ...interiorpoints, endpoint]; } 

this returns array of 6 points (2 end points + 4 interior points), defines line 5 segments.

you can call function this:

divideintofivesegments({x: 0.27176220806794055, y: 0.7258064516129032}, {x: 0.6303191489361702, y: 0.348993288590604}); 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -