This site uses strictly necessary cookies. More Information

X- Home /

# How to get the right equation of and edge normal in motion?

So I have an object that´s being squeezed, changing its localScale in x from 1 to 2 and in y from 1 to 0.5. To achieve this in a realistic way in which movement between frames simmulates this constant area, each vertex moves in a curve to its final position.

Normally, the edge is constant and getting its equation is as simple as getting the cross product of (nextVertex - currentVertex) and the face´s normal. However, because the edge is inclined, its rotation changes along its path. I can´t upload the image, but is the case from above. The edge vector is from the bottom vertex to the top, always aligned at the x axis in this case (though that´s probably going to change), has also a constant depth axis and basically the only thing that changes is the height at both points, which is shown in the image. The edge changes because the top vertex has more depth than the bottom one (even if from this perspective looks like a perfect cube).

So the equation I thought would work was this: startEdgeNormal + (endEdgeNormal - startEdgeNormal) * t; //Which is a lineal transition from start to end where "t" is the frame´s time, that goes from 0 to 1.

But it doesn´t work. I know this because I compared it with a fixed normal that I knew was right at t = 0.5f; However, because am going to use this equation to solve for other variables, I don´t know yet the value of t and therefore I can´t use that method.

When I compared both results, they were similar, but different enough to be considered != by an if statement. I know that comparing equal floats might not work because of their lack of precision; but when we are comparing vectors instead c# still considers very similar vectors equal.

So, is there a better way of getting the edge normal´s equation at time t?

I tried normalizing all vectors first and now even without doing that. Either way they differ.

**Answer** by Feref2
·
Sep 19, 2020 at 10:32 PM

So... I actually found out on my own. See, I was normalizing the edge vectors (not the normals, just the vectors). I did that because I only wanted the check for the rotation without considering the magnitude, but that apparently changes direction. The solution is as simple as never normalizing the edge vectors, then get the cross product.

And, I forgot to mention, also using th t variable of the opposite axis, because in this case only y changes and the right equation that I used checked the normal based on x.

From your question it's completely unclear what kind of curve you're using. The normal completely depends on that fact. A linear interpolation would only work if you used a quadratic bezier curve. The way you usually calculate the normal is to first obtain the tangent at t. The tangent equation for a bezier curve is simply the first derivative of the curve equation you're using. So if you use a quadratic bezier curve the tangent curve is linear. If you use a cubic bezier, the tangent equation will be quadratic.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Looking for a way to solve a 4th degree polynomial equation with constraints at runtime 1 Answer

How can I get back a hit? 1 Answer

How to detect terrain's mesh normals at given point? 0 Answers

How to extend a Material Shader so that it also maps the Normal Maps in WorldSpace? 1 Answer

Rotation Transform to face character AND normal to terrain 2 Answers