## Reflect a vector in relation to another vector

Member
Posts: 96
Joined: 2011.07
Post: #1
Hey,

I'm stuck with a geometrical problem. I have vector A and vector V. I need to find vector A' that is the reflection of A in relation to V (see pic).

respect,
pk

iFrog is coming.
Moderator
Posts: 916
Joined: 2002.10
Post: #2
in 2D or 3D space?
Member
Posts: 96
Joined: 2011.07
Post: #3
2D space.

respect,
pk

iFrog is coming.
Moderator
Posts: 1,563
Joined: 2003.10
Post: #4
This one's pretty simple:

Code:
```float Vector2_dot(Vector2 vector1, Vector2 vector2) {     return vector1.x * vector2.x + vector1.y * vector2.y; } Vector2 Vector2_reflect(Vector2 vector, Vector2 normal) {     Vector2 result;     float dot;          dot = Vector2_dot(vector, normal);     result.x = 2 * dot * normal.x - vector.x;     result.y = 2 * dot * normal.y - vector.y;     return result; }```
Member
Posts: 96
Joined: 2011.07
Post: #5
Awesome. Just trying it out (too many side quests).

...

Hey it's working !!! Thanks.

respect,
pk

iFrog is coming.