Math in Unity : Planes (Part I)

While the line is represented by a point and a Vector, the plane is represented by a point and two Vectors.

If for example we have a Point A and two Vectors, v and u, to find the Point B in any point of the plane is

B = A + v*s + u*t

Now, the parametric form of the plane is

P(s, t) = A + v*s + u*t

Let’s start from the formula to make a code example, and you will see that it will be less complex than it seems.

Let’s take a first example to better understand:
we say that our Point A is (1, 2, 3),
the Vector v is (0, 2, 1)
and the Vector u is (3, 4, 2).
If we apply the formula

P(s, t) = A + v*s + u*t = (1, 2, 3) + (0s, 2s, 1s) + (3t, 4t, 2t) =(1 + 3t, 2 + 2s + 4t, 3 + 1s + 2t)

As always, the formulas can seem very complicated.
Let’s test a simple code to see how to make a Plane from scratch!

First we create a simple scene with three cubes representing the point and the two Vectors

Set the scene, we create a new script called Plane.

Inside it, we create five variables, three for points and two that represent two Vectors.
And we also create a Constructor, since a plane, as we said, is made up of a point and two Vectors.

In the constructor, I created three distinct points, and assigned v and u respectively to the distance between B - A and C - A
In this way we are setting A as the origin point and AB and AC as Vectors.

Now comes the part that interests us: applying the formula of the Plane.

We create the method, PlaneFormula(), and pass the two parameters we need: s and t.

Inside, what we’re going to do is very simple:
P (s, t) = A + v * s + u * t

Translated into code

As we see, the formula is literally copied and pasted on each axis.

In the next article we finish the Plane!