astropanic
astropanic

Reputation: 10939

cutting segment algorithm

I have a segment defined by two points: [x1,y1], [x2,y2].

What is the simplest method to cut it in two parts in a ratio between (1/2) and (1/4) ?

I want the coordinates of the third point [x3,y3] which cuts the above segment in two seperate parts ([x1,y1] , [x3,y3]) and ([x3,y3], [x2, y2])

I search for a very fast method, it must not be to accurate, the coordinates of the third point can be rounded up to integers.

Upvotes: 1

Views: 228

Answers (1)

Christian
Christian

Reputation: 4375

Thats just math, no complex algorithm needed.

[|(x2 - x1)| / 2 + x2, |(y2 - y1)| / 2 + y2] gives you the cut at (1/2).

[|(x2 - x1)| / 4 + x2, |(y2 - y1)| / 4 + y2] gives you the cut at (1/4).

Upvotes: 5

Related Questions