All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > General
Limited reflections (Posted on 2019-02-19) Difficulty: 2 of 5
Triangle ABC has vertices A=(0, 1), B=(1, 0) and C=(0, 0) in the coordinate plane.

The insides of the sides are lined with mirrors, and then a laser beam is fired from the origin with a slope of 314/379

Which corner of the triangle will the laser beam hit first?

No Solution Yet Submitted by Danish Ahmed Khan    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Confirming and counting reflections.... Comment 7 of 7 |

While I have not yet quite grokked all the math involved, I wrote a ray-tracing simulation for this triangle, starting from the origin with any slope. I experimented with rational slopes. 

The program results confirm that the analysis in the postings heretofore are all correct, except for my own original post, where I was dead wrong! :-). 

Also, while confirming them, I can add a bit to Steve H.’s rules: 

If numerator and denominator are both odd, the answer is (0,0) after (2d + n - 2) reflections;

If numerator is even, the answer is (1,0), after (2d + n - 3) reflections;

If denominator is even, the answer is (0,1), after (2d +n - 3) reflections,

where n/d is a reduced fraction. 

A plot of 1/5 is here, 13/19 is here, and the first 30 rays of 314/379 are here.

(This also confirms Charlie’s result of 1069 reflections for the original puzzle.)

The ray-trace program follows. As Charlie pointed out (I think) there are only 

4 possible slopes. Since CA and CB in reflections negate the slope and 

AB inverts it - all rays have slope +/-(m) or +/-(1/m) where m is the original n/d.


Examples and program: 

input num, denom

314 379

  1 0 after         1069  reflections

  input num, denom 

2 67

  1 0 after          133  reflections

  input num, denom

3 91

  0 0 after          183  reflections

  input num, denom

13 22

  0 1 after           54  reflections

 

rabbit-3:~ lord$ more mir.f

        program mir

        implicit none

        integer ori,dest,i,cnt,max

        real*8  x3,y3,x4,y4,xxx,yyy,dxxx,dyyy,delta,oldm,newm,n,d

        call delold('mirror.txt')

        open(20,file='mirror.txt',status='new')

        write(20,4)0.,0.,1,0.,1.,2,1.,0.,3,0.,0.,4

4       format(2(f7.3,1x),i4)

        delta=0.1

3       print*,' input num, denom'

        read*,n,d

        if(n.eq.0)stop

        newm=n/d

        cnt=-1

        max=100000

c       max=30

        x3=0

        y3=0

        x4=delta

        y4=x4*newm

        ori=1

1       cnt=cnt+1

c       print*,' going in - cnt = ',cnt

           if(cnt.eq.max)then

           print*,'reached max ',cnt,' reflections'

           stop

           endif

        oldm=newm

        call intersect(ori,dest,x3,y3,x4,y4,xxx,yyy)

        write(20,4)xxx,yyy,cnt+4

           if(abs(xxx).lt.1e-5.and.abs(yyy).lt.1.e-5)then

           print*,' 0 0 after ',cnt,' reflections'

           go to 3

           endif

           if(abs(xxx-1.).lt.1e-5.and.abs(yyy).lt.1.e-5)then

           print*,' 1 0 after ',cnt,' reflections'

           go to 3

           endif

           if(abs(xxx).lt.1e-5.and.abs(yyy-1.).lt.1.e-5)then

           print*,' 0 1 after ',cnt,' reflections'

           go to 3

           endif        

 if(dest.eq.3)newm=1./oldm

        if(dest.eq.1.or.dest.eq.2)newm=-oldm

        ori=dest

        x3=xxx

        y3=yyy

c       print*,cnt,xxx,yyy

        x4=x3+delta

        y4=y3+delta*newm

        go to 1

        end


        subroutine intersect(ori,dest,x3,y3,x4,y4,xxx,yyy)

        implicit none

        integer i,ori,dest,select(2,3),i1,i2,step,havedest

        real *8 

        1 x1,y1,x2,y2,x3,y3,x4,y4,xx,yy,p(2,2,3),term1,term2,termd,

        1 xxx,yyy

        data p/0,0,0,1,0,0,1,0,0,1,1,0/

        havedest=0

        i1=mod(ori,3)+1

        i2=mod(ori+1,3)+1

        step=i2-i1

           do i=i1,i2,step

           x1=p(1,1,i)

           y1=p(2,1,i)

           x2=p(1,2,i)

           y2=p(2,2,i)

c          print 2,ori, i,x1,y1,x2,y2,x3,y3,x4,y4

2          format(' ori des x1     y1     x2     y2',

        1  '     x3     y3     x4     y4',

        1  /, i2,1x,i2,1x,8(f5.2,2x))

           term1=x1*y2-y1*x2

           term2=x3*y4-y3*x4

           termd=(x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)

c          print*,'term1 term2 termd ',term1,term2,termd 

           xx=(term1*(x3-x4)-(x1-x2)*term2)/termd

           yy=(term1*(y3-y4)-(y1-y2)*term2)/termd

c          print*,'ori dest xx, yy ',ori,i,xx,yy

                if( (i.eq.1.and. 0.le.yy.and.yy.le.1)    .or. 

        1           (i.ne.1.and.( (x1.le.xx.and.xx.le.x2).or.

        1                         (x2.le.xx.and.xx.le.x1) ))) then

                   if(havedest.eq.0)then

                   dest=i

                   havedest=1

                   xxx=xx

                   yyy=yy

c                  print*,dest,xxx,yyy

                   else

                   dest=i

                   xxx=xx

                   yyy=yy

c                  print*,'two destinations!'

                   endif

                endif

           enddo

           if(havedest.eq.0)then

           print*,'found no intersection!'

           stop

           endif                

c       print*,ori,i1,i2,step

        return

        end


        subroutine delold(name)

        character*10 name

        logical ex

        inquire(file=name,exist=ex)

        if(ex.eqv..true.)then

        open(10,file=name,status='old')

        close(10,status='delete')

        endif

        return

        end

Edited on February 22, 2019, 7:57 pm
  Posted by Steven Lord on 2019-02-21 22:51:43

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information