Skip to main content
. 2024 Jun 8;24(12):3735. doi: 10.3390/s24123735
Algorithm 5 Generate Random Point on Line
  •   1:

    function GenerateRandomPointOnLine(point_a, point_b, randomness)

  •   2:

        t Random number between 0 and 1

  •   3:

        x(1t)×point_a.x+t×point_b.x

  •   4:

        y(1t)×point_a.y+t×point_b.y

  •   5:

        Calculate the directional difference dx, dy between point_b and point_a

  •   6:

        Determine perpendicular direction perp_dx, perp_dy

  •   7:

        Normalize the perpendicular direction

  •   8:

        Calculate random_distance based on randomness

  •   9:

        Adjust x, y coordinates by applying random_distance in the perpendicular direction

  • 10:

        return x, y

  • 11:

    end function