blog podcast

The Simple Work

It astonishes me how much work it is to write even what you feel like is a simple library. I just worked some more on my geometry library. My aim is to implement a method that can separate one polygon from another polygon in a given direction. To do this, I’ve gone about implementing a method that can separate a line segment from another line segment in a given direction. This method will be the basis on an iterative method that moves one of the polygons in the correct direction until it no longer overlaps the other polygon. The thing is that this method made me see a lot of basic functions that I was missing on my Vector class and Line Segment class. They are all simple methods, like adding or subtracting vectors from each other, but writing them up together with their tests still takes time.

Code of the Day

  /**
   * Returns the perpendicular component vector of this vector compared to another vector.
   */
  perpendicularComponentTo(other: Vector): Vector {
    if (other.isNullVector()) {
      return this;
    }
    const otherNormed = other.normed();
    const factor = this.dot(otherNormed);
    return this.minus(otherNormed.scale(factor));
  }