Draw raycast reflection in cocos2d

I am trying to draw reflection of raycast, and it drives me mad.

I could successfully draw line between origin and destination (the ray cast), I also got normal, which is said to be:
Quote:
the normal vector at the point of intersection


say the origin is O and intersection of ray and another body is I, what is the formula for reflection R?

I searched and tried:
V = (O - I) // the incoming ray vector
R = V + 2(N.V)N

where . means dot product.

but the result looks like the reflection is in the same direction as incoming ray.

Could anyone give me any suggestions? Is there any angle/degree conversion I missed?

Thanks
Could it be as easy as this...
V - 2(N.V)N

Minus instead of plus in other words.
Zoomulator wrote:
Could it be as easy as this...
V - 2(N.V)N

Minus instead of plus in other words.


I tried it, but it is still incorrect:

Image

Or maybe my code is wrong:
Code:
CGPoint dest = ccp(raycastCallback->collisionPoint.x * PTM_RATIO,
                     raycastCallback->collisionPoint.y * PTM_RATIO);
b2Vec2 v = raycastCallback->collisionPoint - body->GetPosition();
         b2Vec2 n = raycastCallback->normalVector;
         float32 dot = b2Dot(n, v);
         b2Vec2 r2 = 2 * dot * n;
         b2Vec2 r3 = v - r2;
         
         CGPoint reflectP = ccp((r3.x) * PTM_RATIO,
                           (r3.y) * PTM_RATIO);
         
         ccDrawLine(dest, reflectP);
I found the problem, r3 is actually the reflection vector, which is destination point of reflection minus collision point, so I have to add it to collision point to get the target point.
Darn it, you beat me to it. Good job! Glad you found it
Zoomulator wrote:
Could it be as easy as this...
V - 2(N.V)N

Minus instead of plus in other words.


Where can I find some info about the theory behind this formula? I'm not sure how and why it works.

Original thread: https://box2d.org/forum/viewtopic.php?t=6670