PDA

View Full Version : Vector intersecting an arc.



deathshadow
04-02-2007, 01:55 PM
I'm calculating a parabola, and need to figure out where a vector would intersect it and at what angle - This is for a lens evaluation program I'm writing and as such I need to know the angle so I can caluclate the reflection (which should be the opposite side of the normal from the intersection on the parabola)

Anybody got a clue?

JSoftware
04-02-2007, 03:23 PM
are we talking 3d or 2d?

deathshadow
04-02-2007, 03:44 PM
are we talking 3d or 2d?

2d is sufficient - if I can figure out 2d, 3d is simple.

JSoftware
04-02-2007, 03:49 PM
Parabola:
y=ax^2+bx+c
Ray:
P=(t*s+x, u*s+y)

function rayIntersect(a,b,c,t,u,x,y: single): single;
var d,s: single;
begin
d := sqrt(power(b*t+2*a*x*t-u,2)-4*a*t*t*(a*x*x+b*x+c-y));
s := -b*t-2*a*x*t+u;
result := min(s-d,s+d)/(2*a*t*t);
end;

function rayNormalSlope(a,b,x: single): single;
begin
result:=1/(2*a*x+b);
end;


rayIntersect will find the parameter s for the ray which will indicate the nearest intersection point.

rayNormalSlope will indicate the slope of the normal at a certain x value on the parabola. Knowing all this it should be trivial to calculate the reflection

Edit: This code is very unsafe, and unoptimized. You should check if values are inside the range of the used functions

deathshadow
06-02-2007, 01:02 PM
Ok, you've got a few more variables in there than I'm used to seeing... I'm not entirely certain where t, u, b and c come into this.

right now, I'm calculating my parabola

y=ax^2

where A is half the distance between the focus and the directrix...

with the 'ray' I have the origin (x,y) and the slope (s)... not certain how to plug that in to what you posted as I've no clue what t and u are in your example.

is u in your example simply 1/t? What are your b and c defined as?

... and thanks for the help - I've got a very basic understanding of what I'm trying to do here... A LOT of the formula's in the books on the subject seem to prattle on and on about theory without any examples of actual application. (Yes, I'm an impatient sort who threw away the 'users guide' in the TP releases and dove right for the 'language reference' book)

JSoftware
06-02-2007, 02:42 PM
You can discard the b and c parameters as they only have something to do with the placement of the parabola.

t and u is the "velocity" of the point of the ray. You can indeed just set t=1 and u=s