Two points have polar coordinates as follows: θ=130°,r=.35 (point A) and θ=70°,r=.6 (point B). There is a surrounding circle, r=1, that acts as a mirror, and you wish to send a light ray from point A to point B by bouncing it once off the circle. What two alternative directions could you send it in (use an angular measure paralleling the θ coordinate it would have if directed from the origin)?
The following program iterates to the same solutions SilverKnight found with Excel's solver:
DECLARE SUB rect2pol (x#, y#, r#, theta#)
DECLARE FUNCTION norm# (x#)
DECLARE SUB pol2rect (r#, theta#, x#, y#)
DEFDBL A-Z
DIM SHARED pi, dr
pi = ATN(1) * 4
dr = pi / 180
CLS
dir = 90
dir(1) = dir
GOSUB evalu
diff(1) = norm(reflection - incidence)
dir = 88
dir(2) = dir
GOSUB evalu
diff(2) = norm(reflection - incidence)
DO
slope = (diff(2) - diff(1)) / (dir(2) - dir(1))
amt = -diff(1) / slope
dir(3) = dir(1) + amt
dir = dir(3): GOSUB evalu: diff(3) = norm(reflection - incidence)
dir(1) = dir(2): diff(1) = diff(2)
dir(2) = dir(3): diff(2) = diff(3)
LOOP UNTIL ABS(amt / dir(1)) < 1E-14 OR diff(1) = 0
PRINT \"Aim direction=\"; dirA
dir = 270
dir(1) = dir
GOSUB evalu
diff(1) = norm(reflection - incidence)
dir = 272
dir(2) = dir
GOSUB evalu
diff(2) = norm(reflection - incidence)
DO
slope = (diff(2) - diff(1)) / (dir(2) - dir(1))
amt = -diff(1) / slope
dir(3) = dir(1) + amt
dir = dir(3): GOSUB evalu: diff(3) = norm(reflection - incidence)
dir(1) = dir(2): diff(1) = diff(2)
dir(2) = dir(3): diff(2) = diff(3)
LOOP UNTIL ABS(amt / dir(1)) < 1E-14 OR diff(1) = 0
PRINT \"Aim direction=\"; dirA
END
evalu:
pol2rect 1, dir, x, y
' PRINT \"x=\"; x; \"y=\"; y
pol2rect .35, 130, Ax, Ay
pol2rect .6, 70, Bx, By
rect2pol x - Ax, y - Ay, dist, dirA
' PRINT \"Aim direction=\"; dirA
incidence = dir - dirA
rect2pol x - Bx, y - By, dist, dirB
reflection = dirB - dir
' PRINT norm(incidence), norm(reflection)
' PRINT \"--\"
RETURN
FUNCTION norm (x)
n = x
DO UNTIL n > -180
n = n + 360
LOOP
DO UNTIL n <= 180
n = n - 360
LOOP
norm = n
END FUNCTION
SUB pol2rect (r, theta, x, y)
x = r * COS(theta * dr)
y = r * SIN(theta * dr)
END SUB
SUB rect2pol (x, y, r, theta)
r = SQR(x * x + y * y)
IF x = 0 THEN
theta = 90 * SGN(y)
ELSE
theta = ATN(y / x) / dr
END IF
IF x < 0 THEN theta = theta + 180
END SUB
which finds
Aim direction= 64.92641251550131
Aim direction=-76.70421326480458
|
Posted by Charlie
on 2003-11-23 23:03:32 |