What is a quaternion, and do how they work? Also, what advantages do you gain using three points on a 2D plane? Finally, when is it considered good practice to use quaternions?
Mathematically, a quaternion is a complex number with 4 dimension. But in game development, Quaternions are often used to describe a rotation in 3d space by encoding:
- a rotation axis (in form of a 3-dimensional vector)
- how far to turn around that axis
Note that this information is encoded with sines and cosines inside the quaternion, so in general you shouldn't try to explicitly set or read the quaternion's internal components (x y z w) individually. It's easy to make a mistake that way and get a non-meaningful result. A quaternion math library will usually provide functions to operate on quaternions (eg. converting them to & from Euler angles or axis-angle), which ensures the math is correct and has the side benefit of making your code easier to read and understand.
An alternative way to describe rotations is by describing how far to turn around the 3 fixed axis' x, y, and z (aka Euler angles) which only requires 3 numbers instead of 4 and is usually more intuitive to use. However, euler-angles are subject to a problem called gimbal-lock: When you rotate 90° around one axis, the other two axis become equivalent. With quaternions, this problem does not occur.
Another way to express rotations in 3d space is with a 4x4 transformation matrix. But with a transformation matrix you can not just rotate, but also scale, translate and skew. When you want only rotation, a matrix would be overkill and a quaternion a much quicker and simpler solution.
This problem is only relevant in 3d space. In 2d space, you only have one rotation axis. Any rotation can be expressed with a single floating-point number or a single complex number, so you don't have this problem. While you can theoretically express a rotation on a 2d plane with a quaternion where the axis points into (or out of) the plane, it is usually overkill.
This is to add to @Philipp's answer.
Also, what advantages do you gain using three points on a 2D plane?
You don't really need quaternions if all you're interested is in rotating on the plane, i.e. about the z axis. In this case, all you need is the yaw angle, and you can exploit the fact that successive rotations about the z axis commute. So you can apply your rotations in any order you wish.
The situation is different if you're rotating on a plane that's not the XY plane. This rotation is equivalent to rotating about an arbitrary 3D axis. Now, you have two choices:
rotate your plane in 3D so that it coincides with the XY plane and then yaw, and transform back , or
think of your rotation as being in 3D to begin with.
The second choice is easier to code. As @Philipp said, quaternions avoid gimbal lock (if you avoid intermediate RPY or axis/angle conversions).
Finally, when is it considered good practice to use quaternions?
Whenever there are 3D rotations, it's good practice to use quaternions.