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).

[Image: reflect.jpg]

respect,
pk

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

respect,
pk

iFrog is coming.
Quote this message in a reply
Moderator
Posts: 1,560
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;
}
Quote this message in a reply
Member
Posts: 96
Joined: 2011.07
Post: #5
Awesome. Just trying it out (too many side quests).

...

Hey it's working !!! Thanks.

[Image: l.jpg]

respect,
pk

iFrog is coming.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Vector shapes Miglu 16 8,263 Sep 22, 2010 07:52 AM
Last Post: Miglu
  Signed Distance Fields for Alpha Tested Magnification of Vector Textures maximile 2 5,624 Mar 29, 2010 10:59 AM
Last Post: Skorche
  New to obj-c and have no idea where to start: vector graphics billybob 1 2,572 May 27, 2009 11:17 AM
Last Post: billybob
  Vector graphics rendering: Best approach? Luipaard 5 4,962 Sep 28, 2007 08:40 AM
Last Post: TomorrowPlusX
  Vector (Normal) Map blending operations? kelvin 10 6,581 Mar 16, 2007 04:31 PM
Last Post: OneSadCookie