Angular type-safe physical units

Recently we have seen how we can create our own types to encapsulate physical concepts such as position, velocity, timespan and more. We developed all the types needed for movement in one and two dimensions, however so far we have not talked about rotation.

Today we will look at how to implement the types necessary to also gain the advantages of type-safety when it comes to the rotation and orientation of an object.

We will consider only the two dimensional case, since it is relatively straight forward. However, a similar approach could be taken in three dimensions as well, though it would significantly complicate the mathematics.

Continue reading →

Angles, directions, and their binary representation

Something that probably every game developer has worked with at one time or another – and some of us might work with it daily – is angles.

Angles are used to represent directions and rotations and especially in 2D they are an easy way of doing so, since only a single number is needed to represent an orientation.

In 3D we need three angles – pitch, yaw and roll -, making it slightly more complicated.

In this post I want to explore the way we represent the concepts of angle, direction, orientation and rotation.

Continue reading →