blog podcast

On Change

I’m working on my beloved little geometry library. I’m finally approaching the goal I set up a long time ago, I want to write a small layout library that can layout components so that they don’t overlap. As part of this I want to be able to visualize vectors. To visualize vectors I want to draw a line and a triangle, the triangle indicating where the vector points. To draw a good pointing triangle I want to be able to rotate shapes, so that the triangle points in the right direction. To do a good rotation I want to first transpose my points to Origo and then apply a rotation matrix. And to do all of these things I realize that I’d rather work with my vectors as three dimensional as two dimensional.

Why? Because when you represent 2 dimensional points with three components you can easily apply tranlation opearations combined with rotation operations on the vectors as a simple matrix multiplication. But here comes my big sorrow. I’ve created a matrix class that is always 2x2. So I need to refactor. It’s an interesting problem actually. I now want to suppose both the old 2x2 matrix that I used before, as well as the new 3x3 matrix that is good to perform transformations with. I’m still not sure on how the end result will be, but my current solution is to have one general matrix class, and then I create one Matrix2x2 and one Matrix3x3 that allow simple handling of my geometric operations.

Code of the Day

This is the simple implementation, not taking the pivot point into account that’s breaking my patterns.

  rotate(pivotPoint: Point, degrees: number): Point {
    const rotationMatrix = Matrix.rotationDegrees(degrees);

    return rotationMatrix.times(this.asVector()).asPoint();
  }