pointInBetween method

Coord pointInBetween(
  1. (num, num) ratio
)

Returns the point in between whose distance from first point and from second point is in the given ratio.

This function uses the section formula, assuming ratio = (m : n) :-

x = (mx2 + nx1) / (m + n)

y = (my2 + my1) / (m + n)

Note:- (m + n) should always be positive.

This can also be used to calculate the external point, by setting either 'm' or 'n' negative, appropriately, ensuring (m + n) is positive.

Implementation

Coord pointInBetween((num, num) ratio) {
  final denominator = ratio.$1 + ratio.$2;
  assert(denominator > 0, '(m + n) should be +ve but found $denominator');
  return (
    (($1.$1 * ratio.$2) + ($2.$1 * ratio.$1)) / denominator,
    (($1.$2 * ratio.$2) + ($2.$2 * ratio.$1)) / denominator,
  );
}