The Artima Developer Community
Sponsored Link

Java Answers Forum
calculate reflection

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Oleg

Posts: 1
Nickname: hsikur
Registered: Apr, 2003

calculate reflection Posted: Apr 20, 2003 8:53 AM
Reply to this message Reply
Advertisement
Hi

I have a problem with calculating the reflection of a ray from the mirror. I can do it if I know the angle that I used to turn the mirror, but then if I have more than one mirror I have a problem to calculate the right angle.
So, I'm thinking to use coordinate transformation to calculate reflection.

Anybody can help?

/* code that I use now */
public void paint(Graphics g)
{
// initial mirror coordinates
double mirror[] = { 120.0, 80.0, 120.0, 160.0 };

// initial ray coordinates
double ray[] = { 20.0, 120.0, 120.0, 120.0 };

// angle to turn the mirror
double angle = Math.toRadians(30);

// placeholder for new mirror coordinates after transformation
double mirror_new[] = new double[4];

// placeholder for coordinates of reflected ray
double reflect[] = new double[4];

// set turn angle for the mirror
AffineTransform at = new AffineTransform();
at.setToRotation(angle, 120, 120);
at.transform(mirror,0,mirror_new,0,2);

// draw mirror after turn
g.drawLine((int)mirror_new[0],(int)mirror_new[1],
(int)mirror_new[2],(int)mirror_new[3]);

// draw ray
g.drawLine((int)ray[0],(int)ray[1], (int)ray[2],(int)ray[3]);

// calculate reflection
// ???????
at.setToRotation(angle * 2, 120, 120);
at.transform(ray,0,reflect,0,2);
// ??????

// draw reflection ray
g.drawLine((int)reflect[2],(int)reflect[3], (int)reflect[0], (int)reflect[1]);
}

Thanks,
hsikur

Topic: Editing a data file Previous Topic   Next Topic Topic: Adding Java Applet to E-mail

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use