PDA

View Full Version : how to caculate a line's reflected ray


flyingaway
08-27-2009, 03:21 AM
the reflection plane maybe is a line ,an arc or some other 2D geometric drawing

magicm
08-27-2009, 05:17 AM
Not sure if I understand the question; Is this what you're trying to do? You have a shape, an incoming vector that hits the shape at some arbitrary point, and you want to calculate the reflection vector at that point? Please elaborate.

Martijn

flyingaway
08-28-2009, 01:35 AM
yes , just as you said , is there some methods to realize it ?

magicm
08-28-2009, 08:43 PM
When your shapes are actually curved, it's not an easy task to find the intersection point, for straight lines it's a lot simpler. I don't have the time to write that code for you right now, but this (http://alienryderflex.com/intersect/) should get you started.

Calculating the reflection vector is pretty easy, here's an example:
-- Get tangent vector halfway Line01
pathVec = tangentCurve3D $Line01 1 .5

-- Get vector from Line02
rayVec = normalize ((getKnotPoint $Line02 1 2) - (getKnotPoint $Line02 1 1))

-- Calculate reflection vector
reflectionVec = 2 * (dot -rayVec pathVec) * pathVec + rayVec
This code assumes you have 2 lines in your scene, one named Line01 (the "mirror" shape) and one named Line02 (the "ray" shape)..

Hope this helps,
Martijn

CGTalk Moderation
08-28-2009, 08:43 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.