1

What i'm trying to do is compare Normal vectors to know if multiple surfaces are positioned at the exact same direction and if not then to be able to tell how close in direction to each other they are by the difference in their Normal values. So thats why i need to know the answers to 1st & 2nd Paragraphs below if that will also help u to help me obtain the answers to the two questions 1st & 2nd below.

So 1st: If i have a negative normal value to use in C++ coding does it also indicate the direction of that surface.

2nd: If i use Cross Product to find the Normal of a Triangle Surface with vertices p1, p2, p3 its gonna look something like this:

A= p2 - p1 & B= p3 - p1

Nx = Ay * Bz - Az * By
Ny = Az * Bx - Ax * Bz
Nz = Ax * By - Ay * Bx

So if for example Nx equals a negative value how would i process it? Cuz to what i understand negative values cannot work cuz normal values are perpendicular to surfaces and have to be positive to be processed with a Light source vector. So what i saw on another post on this site: (OpenGL how to manage negative normals?) was them iqnoring the negative value ( I THINK )and treating it like a positive to give a positve result that can be processed. I could be wrong thats why im trying to clear that up as well.

user438383
  • 5,716
  • 8
  • 28
  • 43
  • Please [edit] your question and put 3rd in the beginning. Your use case is more important because your questions are based on your context. – Louis Go May 09 '22 at 02:38
  • 1
    You have to calculate the dot product of the normals of the surfaces, the directions of which you want to compare. If you normalized (divided by magnitude) the two normal vectors first, you get a value within -1..1, giving the cosine of the angle 180°..0°. If this result is negative then the surfaces point to opposite directions. Each surface may have an outside and an inside direction. Depending on your application and whether the triangles are defined consistently with that in mind, you would judge those surfaces as pointing to a different or to a similar direction (if both sides are equal). – Sebastian May 09 '22 at 04:55
  • Hey @Sebastian when u say " If you normalized (divided by magnitude) the two normal vectors first, you get a value within -1..1, giving the cosine of the angle 180°..0°." Do u mean Nx and Ny while not doing Nz yet? – Gore District May 09 '22 at 10:41
  • You want to compare two surfaces defined by triangles. With the cross product you get a normal vector for each, which you normalize to length 1 (you still have two vectors with 3 components each). Then you take the dot product of those two vectors giving you a scalar number between -1..1, which is the cosine between the two normals. – Sebastian May 09 '22 at 10:59
  • Ok so what i understand you're saying is that i 1st get the Normal vector of each triangle by Cross Product( Which i'll call N & N2). Then i find the magnitude of N then N2 then divide each of their X,Y, Z components by their own respective magnitudes e.g: Nx/|N|, Ny/ |N|, Nz/ |N| for N then i do the same for N2 . This will give a Unit Vector for each. Then i should perform a Dot Product between N & N2's unit Vectors which will result in a cosine Angled result. Did i misunderstood anything or did i got u 100% @Sebastian ? – Gore District May 09 '22 at 14:29
  • 100 Percent! You just have to decide, what to do with negative results. If your triangles distinguish between inside and outside (then `1 ≠ -1`, do nothing) or inside and outside is treated the same (then take absolute value of result). The higher the result (1 is max.), the more parallel the surfaces. `cos 0° = 1`. – Sebastian May 09 '22 at 14:52
  • Ahh so @Sebastian that means that if i have a negative value from Normalization i should just flip it to positive if i dont want to check inner faces? Like if i have a value -0.4623. A negative result from Normalization i just remove the minus sign from before the value (0.4623) and it's all good? – Gore District May 09 '22 at 17:26
  • Depends on your application. If you flip it, the inner faces are changed to outer ones. If you do not flip it, you can still see in the results that the two surfaces are opposite to each other, which often is useful. The maximum angle with flipping is 90°, the maximum angle without flipping is 180°. Removing the minus sign is the `abs(x)` function. – Sebastian May 09 '22 at 17:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244620/discussion-between-gore-district-and-sebastian). – Gore District May 09 '22 at 20:03
  • Hi again@Sebastian . Just realized something. If i get the angle between the 2 Normals it might not be relative between the 2 surfaces in term of their locations as well. Only to their perpendicularity. So i was thinking if u thought the same way too? Cuz what im thinking is to simply add the normalized values to the positional vertices to make them also relative to the surfaces perpendicularity (I think). Then do the dot product for the angles from there. So what u think? Is my concern Valid? – Gore District May 14 '22 at 00:09
  • You only wrote about direction. If you also want to compare position, what should the result be as a number? You could compare direction and position separately. If you do it in a combined way, you have define, what you want? An angle, a distance, something projected, a distance in 6D space for surfaces of all positions and orientations? (So result would be `sqrt(diffPos² + diffOrient²)`? Does a good orientation compensate the wrong position to a certain degree? – Sebastian May 14 '22 at 04:35
  • I would prefer them separately. The Direction & Position cuz thats easier to me. I've ran some Xperiments with the help u gave me and everything looks right. But now that i think about it the normal vector is a 4th vertex proceeding from the 3 points of an already existing 3D vector so comparing it with another from a different face should be relative to vertex position as well. Its just that i think i was confused with a normalized vector which will always be <= 1. Cuz if that was the case how would a 3D vector like (26,42,34) be compared with another 3D vector who's components is <=1. – Gore District May 14 '22 at 06:10
  • I would not add the direction vector and the position. With a slightly different position you would potentially compensate for a totally different direction. Then your test would overlook the wrong direction. – Sebastian May 14 '22 at 06:55

0 Answers0