I am going to write an graphical 2D application that allows user to create polygons and transform them through transformation such as rotation an so on. I was hoping someone can give pro and cons arguments for the different choices I got in my mind. (Its all in Java btw!)

a). Represent vectors by filling matrices with 'real' numbers. This means making a matrix datas tructure that supports multiplication, transposing etc

b). Make a own vector class, such that I can make a matrix class that support those vectors.

  • I don't see how a) and b) are different. At the end of the day you are still going to manipulate arrays of numbers?
    – user7146
    Sep 21, 2012 at 20:56

3 Answers 3


My personal preference (for my own personal project) is to have separate classes for matrices and vectors. This allows the language to do a bit more typechecking than if everything was a matrix.

  • Yes, having the compiler to verify that you multiply a 'horizontal' vector to a square matrix and a square matrix by 'vertical' vector would be very welcome to me.
    – 9000
    Sep 21, 2012 at 18:24

For 2D transforms you only need 2-tuple vectors and a 2x2 matrix. Both are trivial to implement. Things like matrix to vector multiplication would take a one-line formula rather than a proper loop.

Since matrices are so small I think it would be easier to store 4 numbers in a matrix and not a list of vectors. At least I'd try this approach first. If you need you can directly accept vectors in a constructor or a factory method (e.g. to create an offset matrix).


It seems like you just need

struct xy {float x; float y}


class affine_transformation
  float m[6];

  xy transform(xy input) {...}
  methods rotate(), shear(), scale(), translate()

See http://www.willamette.edu/~gorr/classes/GeneralGraphics/Transforms/transforms2d.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.