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().
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.
Now that we have seen the 2D perpendicular Vector, we can move on with our calculations.
If you remember, we stuck with this formula
For now, the only way to solve the problem with t and s is to remove one of the two from the equation.
We start with t…
Today we talk about intersections.
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?
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…
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
Now, the parametric…
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…
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