Some one sent me email asked me how to calculate reflected ray?

Please refer to the attached image.
Assume we know the reflect point O, and the incoming vector a ([b]AO[/b]) and the vector b ([b]OB[/b]).
If only normal vector of [b]b[/b] is known, i.e. know the direction but did not know the length.
Length |[b]b[/b]| can be calculated with inner product between [b]a[/b] and unit vector of [b]b'[/b].
For example: [b]a[/b]=(ax,ay), [b]b'[/b]=(bx',by'). Then, the length of [b]OB[/b] = (ax*bx'+ay*by')/sqrt(bx'*bx'+by'*by');
So you can calculate vector [b]b[/b]=(bx,by)=(bx'*OB, by'*OB);
Vector [b]AB[/b]=[b]AO[/b]+[b]OB[/b]=[b]a[/b]+[b]b[/b]
The out going ray [b]OC[/b]=[b]OA[/b]+[b]AC[/b] =-[b]AO[/b]+2*[b]AB[/b]=2*([b]a[/b]+[b]b[/b])-[b]a[/b]=[b]a[/b]+2*[b]b[/b]

Bold face represents vector.