Function perpendicularBalancedSegment

  • Parameters

    • polygon: [number, number][]

      a convex polygon as an array of 2D points, each point an array of numbers

    • line: VecLine2

      a line in the form of a vector and origin

    • Optional point: [number, number]

      an optional point along the line through which the perpendicular line will pass.

    Returns [number, number][]

    a segment as an array of two points.

    Description

    Given a polygon and a line which passes through it, create a segment perpendicular to the line which fits nicely inside the polygon, but is also balanced in its length on either side of the input line, so, whichever side of the perpendicular segment is the shortest, the other side will be equal in length to it. By default the midpoint of the line (the line's segment inside the polygon) will be chosen to build the perpendicular line through, if you like, you can specify this point.