About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
Maths in EE: Similarity between normal vectors
Author Message
Chris Offline
Member

Post: #1
Maths in EE: Similarity between normal vectors
Hi,

Simple question - given two normal vectors (x,y,z is between -1 and 1), how can I compute the similarity between them in EE?

is that what AbsAngleBetween is for? or should I be doing it some other way than:

if (AbsAngleBetween(nrm1, nrm2) < PI/2) // does this mean they're within 180 degrees similarity?

1. I want to detect how much they're facing the same direction - but it's a bit hard to test if its working, so thought i'd make a post.

2. Less important: Is there a "best way" to make them, over time, make them join into one normal - or do I just keep lerping them towards the average of each other etc.

Thanks,
-Chris
12-11-2010 03:17 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #2
RE: Maths in EE: Similarity between normal vectors
1. yeah, absanglebetween is the right choice
2. lerping is simple but it's not mathematically correct, what you want is to compute Cross product between 2 vectors, and then rotate the 1 vector by the Cross direction.

Vec cross=CrossN(a,b); // get normalized cross
a*=Matrix3().setRotate(cross, angle); // or -angle, need to check which one to use
12-11-2010 03:43 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #3
RE: Maths in EE: Similarity between normal vectors
Awesome answers, thank you for your help.
12-11-2010 03:44 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #4
RE: Maths in EE: Similarity between normal vectors
1. Another thing; if I wanted to get the normal vector between a set of normals of size n, how do I mathematically correctly rotate it towards the set without using averages - or should I use them at one point (if so, i'm not sure where)?

2. Also how do you mean I check the -angle in your above comments - do I check which one is closer to the side of 180 somehow?

Thanks, i'm getting much better results with this.
12-12-2010 01:15 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #5
RE: Maths in EE: Similarity between normal vectors
1.
-calculate average normal of all normals
-for each normal compute cross between i-th normal and average, and rotate it
2. just check +angle and -angle, and see which works correctly, and use that version
12-12-2010 01:55 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #6
RE: Maths in EE: Similarity between normal vectors
Thanks for your fast reply:

1. So you mean something like:

Vec myNormal = // some normal
Vec avgnrm = 0;
UInt count = 0;

FREPA(normals) { // all normals in the set
avgnrm += normals[i];
count++;
}

-calculate average normal of all normals:
avgnrm /= count; // okay, next part:

-for each normal compute cross between i-th normal and average, and rotate it:
// just following your instructions like a machine:
FREPA(normals) {
Vec cross=CrossN(normals[i],avgnrm);
Vec temp = normals[i];
temp*=Matrix3().setRotate(cross, angle); // check +angle -angle etc later
}

- but now what? I don't want to rotate the set towards myNormal (hence creating temp) - I wan't to rotate myNormal towards the set.
- do you mean I should now sum temp and average temp?

Thanks - excuse "pseudo" code.
12-12-2010 02:08 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #7
RE: Maths in EE: Similarity between normal vectors
2. I think it was +angle as "nrm*=Matrix3().setRotate(cross, 0.2f);" - Q. what unit is 0.2f in for angle though - I originally tried "1" thinking it was degrees, but this messed it up quite alot pfft

1. Please can you clarify the end of my averaging problem in the above post - i'm beginning to get amazing results now (so a big thank you!!) - but it needs to be done perfectly. How can I finish it:

"-calculate average normal of all normals
-for each normal compute cross between i-th normal and average, and rotate it"
what next?
12-12-2010 03:41 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #8
RE: Maths in EE: Similarity between normal vectors
I thought you mean move all normals towards the average
12-12-2010 07:00 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #9
RE: Maths in EE: Similarity between normal vectors
(12-12-2010 03:41 PM)Chris Wrote:  Q. what unit is 0.2f in for angle though - I originally tried "1" thinking it was degrees, but this messed it up quite alot pfft

It should be in radians. So, 1 is ~57.3 degrees.
12-12-2010 08:09 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #10
RE: Maths in EE: Similarity between normal vectors
I would like to move myNormal (one normal) towards the "average" of the set. I guess I need to keep the magnitude to 1 - this is why moving them towards to average is resulting in eventually the normal becoming 0, as the magnitude of the cross isn't always 1. But I never learnt about normals - am not sure how to do this in EE.

Please could you help explain it; e.g. rotating myNormal towards the average of the set of normals, without affecting the magnitude?

Thanks.
12-12-2010 09:41 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #11
RE: Maths in EE: Similarity between normal vectors
do avg_normal.normalize(); instead of avg_normal/=count;

Vec cross=CrossN(myNormal,avg_normal);
myNormal*=Matrix3().setRotate(cross, angle); // check +angle -angle etc later

rotating doesn't change the vector length
12-12-2010 09:44 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #12
RE: Maths in EE: Similarity between normal vectors
You mean:

FREPA(normals) { // all normals in the set
avgnrm += normals[i];
}

avgnrm.normalise();

I just tried this - but the result is very wrong - sorry if i'm doing something very silly, I had a long day.

Edit: Oh, sorry I didn't even read the bit under it - thanks it works with:

avg_normal.normalize();
Vec cross=CrossN(myNormal,avg_normal);
myNormal*=Matrix3().setRotate(cross, angle);

I think i'll look at this deeper after sleeping,
Thank you very much for your help today.

Chris
(This post was last modified: 12-12-2010 09:53 PM by Chris.)
12-12-2010 09:50 PM
Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #13
RE: Maths in EE: Similarity between normal vectors
Sorry to bring up something similar to this again, but there are several formulas for this and i'd like to know a efficient way to do it in EE (performance is quite important for this):

Suppose I have a Plane (Vec source, and Vec normal) and I have have another Vec pos infront of this plane. How can I calculate the AbsAngleBetween from the source to the pos, governed by the normal?

   
Attached is a diagram - how to find theta?

(I tried using a closest point on line segment function from pos to normal, and performing basic trig on the right angle triangle.. but it's very inefficient.)

What's a good way to do this in EE?

Thanks so much,
Chris
01-16-2011 10:36 PM
Find all posts by this user Quote this message in a reply
Esenthel Online
Administrator

Post: #14
RE: Maths in EE: Similarity between normal vectors
AbsAngleBetween(normal, pos-source);
01-16-2011 10:42 PM
Find all posts by this user Quote this message in a reply
Post Reply