# Math in Unity : Intersections (Part VI)

Today we will see another example about the lines.
In previous articles we have seen how intersections between segments work, now let’s see how they work between two lines.

We create two lines with new coordinates

# Math in Unity : Intersections (Part V)

In previous articles we have seen what happens when we have two line which intersect one with each other.
But if we have two parallel lines?

Let’s try this :

# Math in Unity : Intersections (Part IV)

Now that we’ve calculated the intersection point, what we need is visual feedback.

In the DrawIntersection script, under the Two Lines, we try to instantiate a sphere at the exact point of the intersection of the two lines.

To do this, we create a float variable and call it
intersectT = to our IntersectionPoint() method and pass the second line as a parameter.

To finish it, we need another method that we have already used in previous articles : LERP().

# Math in Unity : Intersections (Part III)

Time to code!
“Unfortunately” the theory is important, so I had to write two articles about it.

Now, we have seen that to calculate both t and s we need the perpendicular Vector.
First, let’s create a new C # script.

What we need are three variables and a constructor.

# Math in Unity : Intersections (Part II)

Now that we have seen the 2D perpendicular Vector, we can move on with our calculations.
If you remember, we stuck with this formula

# vt = c + us

For now, the only way to solve the problem with t and s is to remove one of the two from the equation.

# Math in Unity : Intersections (Part I)

Probably from now on things will get slightly complicated, but as always, when we know what to do and how to do it, the real difficulty lies in understanding the formulas and translating them into the code.

First of all, what is an intersection?
In a…

# Math in Unity : Planes (Part II)

Now that we have our method, let’s try applying it to our three cubes!

First of all, we need another script to create the plan.
I called it CreatePlane.
Inside, we first of all take the reference of the three cubes and the plane.

So, what we need to create…

# 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…

# Math in Unity : Linear Interpolation(Part II)

What we did earlier was simply create a Move () method and set a position.
It is true that with Time.time the hope moves constantly, but using a simple float the sphere “finds” its position between Point A and Point B.

To create a linear interpolation instead, we have to…

# Math in Unity : Linear Interpolation(Part I)

To better understand linear interpolation, let’s make an example immediately.
Let’s say we have two points, Point A and Point B, and consider the distance between the two points as the Vector v.
Now, we know that the formula for finding Point B is simply
Point A plus the Vector

## 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!

Get the Medium app