Math (in Unity) : Trigonometry, Sin and Cos

Matteo Lo Piccolo
3 min readOct 27, 2021

--

Before moving on, we will talk about the SIN and COS in Trigonometry.
MathF Class does not only contain the Acos method, but obviously all four operations:

MathF.Sin, MathF.Cos, MathF.Asin, MathF.Acos.

I created a new scene in the current project, and I simply recreated a Cartesian plane.
So I created a Vector 2, 3, yellow in color.
This is my scene

And this is my Script.

I attached my script to the Camera

The thing I want to explain is very simple:
we have a Vector (2, 3).
If now the Pythagorean theorem, like this

The result will be this

I created this little rectangle to explain a simple rule:

If we know the angle, and we have one or more Vectors, how do we calculate the point on the X axis and the point on the Y axis?

The formula is:
point x = hypotenuse * cos (angle)
point y = hypotenuse * sin (angle)

The hypotenuse is simply the length of a Vector right?
So basically

point x = length * cos (angle)
point y = length * sins (angle)

As you can see, the SIN is relative to the X axis,
while the COS is relative to the Y axis.

From this formula we can deduce that the coordinates of the Vector can be represented as follows:

Vector v = (||v|| cos(angle v), ||v|| sin(angle v)))

If we had two Vectors, applying the same principle

Vector v = (||v|| cos(angle v), ||v|| sin(angle v)))
Vector w= (||w|| cos(angle w), ||w|| sin(angle w)))

And from this, we can reduce the Dot Product Formula to this :

Dot Product =
(||v|| cos(angle v) * ||w|| cos(angle w) +
(||w|| sin(angle v) * ||w|| sin(angle w))

I don’t know if this kind of information will be useful to you, there are a lot of great references on the Internet about Trigonometry.
Honestly, I know it’s a pretty peculiar type of content, so it doesn’t necessarily need to be useful, unless you have to use a lot of math for your calculations.

See you in the next article!

--

--

Matteo Lo Piccolo
Matteo Lo Piccolo

Written by Matteo Lo Piccolo

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!

No responses yet