# find the closest vector to point

This topic is 1418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys .

every segment which defined by two points there are 2 unit normal vector .

I dont know how to explain it but I would like to find between these two vectors, the vector which is more "looking" to the point .

EC' is the vector that I woudl like to find beacuse he is more looking to Point F .

Edited by MaorNr

##### Share on other sites
The dot products of the vector F-A with the two normal vectors have different signs. Pick the positive one.

##### Share on other sites

Expanding on what Álvaro said, this works because of how the dot product relates to the cosine of the angle between the two vectors in question (F - A, and C - E or D - E).

As found on Wikipedia, the following equation holds:  P·Q = ?P? ?Q? cos ?

If Q is pointing sort of in the same direct as P, as is the case with C - E relative to F - A in your example, then ? will be smaller than 90°, and the cosine will be positive.  If Q is pointing more away from P, like with D - E relative to F - A, then ? will be larger than 90°, and the cosine will be negative.  If Q is neither pointing toward nor away, but is pointing exactly to the side, then the two vectors will be at right angles, and the cosine will be exactly 0.  In that case, neither unit vector will be more toward or away, and you'll have to decide how to handle that edge case.

Note that the length of P and Q are involved, but are irrelevant in your case, since you know that the two unit vectors are exact opposites of each other.  If you were comparing two arbitrary vectors to find out which one is most aligned with a third vector, then you'd have to first divide by the length of the involved vectors so that you could get the cosine term on its own.  Then you'd just select the vector which produced the largest cosine value, as that would be closest to the cosine of 0, because the angle between the two vectors is 0 when the two vectors are perfectly aligned.

Edited by Andy Gainey

##### Share on other sites

The dot products of the vector F-A with the two normal vectors have different signs. Pick the positive one.

Expanding on what Álvaro said, this works because of how the dot product relates to the cosine of the angle between the two vectors in question (F - A, and C - E or D - E).

As found on Wikipedia, the following equation holds:  P·Q = ?P? ?Q? cos ?

If Q is pointing sort of in the same direct as P, as is the case with C - E relative to F - A in your example, then ? will be smaller than 90°, and the cosine will be positive.  If Q is pointing more away from P, like with D - E relative to F - A, then ? will be larger than 90°, and the cosine will be negative.  If Q is neither pointing toward nor away, but is pointing exactly to the side, then the two vectors will be at right angles, and the cosine will be exactly 0.  In that case, neither unit vector will be more toward or away, and you'll have to decide how to handle that edge case.

Note that the length of P and Q are involved, but are irrelevant in your case, since you know that the two unit vectors are exact opposites of each other.  If you were comparing two arbitrary vectors to find out which one is most aligned with a third vector, then you'd have to first divide by the length of the involved vectors so that you could get the cosine term on its own.  Then you'd just select the vector which produced the largest cosine value, as that would be closest to the cosine of 0, because the angle between the two vectors is 0 when the two vectors are perfectly aligned.

thanks you very much guys this method which you explained to me had saved to me many resources !

thanks thanks thanks !

And Alvaro I actually checked it , and it seems like I needed the negative one , thanks alvaro

Edited by MaorNr

##### Share on other sites

EC' is the vector that I woudl like to find

it seems like I needed the negative one

You may want to check your vector math. The EC' vector as shown in the diagram (arrow pointing from E to C') would be formed as (C' - E). Are you perhaps using (E - C') instead?

Edited by Buckeye

##### Share on other sites

EC' is the vector that I woudl like to find

it seems like I needed the negative one

You may want to check your vector math. The EC' vector as shown in the diagram (arrow pointing from E to C') would be formed as (C' - E). Are you perhaps using (E - C') instead?

yes i'm , in the geogebra I did that , but in my code I saw that and I fixed that .

and im really new in non-highschool math

Edited by MaorNr

##### Share on other sites
Actually, I learned this in high school.

##### Share on other sites

Actually, I learned this in high school.

its up to your age, im only 15 :)

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009384
• ### Who's Online (See full list)

There are no registered users currently online

×