Light rays bouncing off shapes!

Hi!

For at project at school, we’re making a drawing board, where the user will be placing different shapes (such as bezier splines, circles, lines, and so on (attachment, (2))), that will be functioning as mirrors. Also, there will be a light source emitting rays, functioning as a light source. When these rays hit the shapes, we want them to bounce off them just as light bouncing off a mirror, regarding to the reflection angles. (attachment, (1)) But we really dont have a clue how we should go about this…

We’ll be needing the tangent of the shape where a ray hits it (probably from the derivative of the shape in the intersection point), and calculate where the ray will go from there by the help of some some angles and rotations and stuff…

We’ve looked around in the API, but we cant seem to find anything that could help us with doing this… or is it?

Attached image should explain what we’re trying to do…

http://hovedprosjekter.hig.no/v2004/data/gruppe11/vinkelillu.gif

EDIT/
After some thinking, we’ve found out that the only thing that we really are wondering about, is how we can find the tangent of a shape in a given point of the shape.
/EDIT

Anyone got some ideas?

Thanks in advance,

Lars Petter

i a given universe ( 3D ) you need the collision point or line between to objects ?

Welcome to the world of mathematics, i studied it at university ( Analysis III was my favorite 3D integrals wow it rocks and my brain was cooking.

i dunno how much skill u have in mathmatics, but it seems u need a good book or a good university.

Search for reflection vector on google. Here is one hit:
http://www.experts-exchange.com/Programming/Game_Development/AI_Physics/Q_20658459.html

But it will be dificult to understand unless you have some knowledge of vector math.

thanks for answers…

i DO know the mathematics, but to calculate the reflection angle, we need the tangent of the shape in the point where the ray hits it. so we wondered if anyone knew of some prewritten stuff that could do that. if not, we can think we can find the intersection point from some graphics2d functions, then combine that point with the function of the shape to get the tangent. but this involves even more mathematics, which we are trying to avoid :).

it’s a 2d space btw, not 3d. =)

  • Lars Petter

The java2d api doesn’t provide the means of finding the tangent to a Shape at a given point, your going to have to write it yourself.

It shouldn’t be that hard though - the tangent of a line or circle at a given point is a trivial bit of maths.
The tangent at a given point of a bezier spline is not gonna be quite so trivial, but im sure there are maths articles on how to do it.
Have a search.