Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
Go Back  Xtreme Visual Basic Talk > > > Simulation Of a light Source and Mirrors...:)


Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2011, 03:31 AM
ashaan55 ashaan55 is offline
Newcomer
 
Join Date: Nov 2010
Location: MU
Posts: 15
Cool Simulation Of a light Source and Mirrors...:)


Hi guys, basically what I am trying to do is to draw a ray of light emitted by a light source and it is going to be reflected mirrors. I rotate the emitter and mirrors and the ray of light shold obey the laws of reflection. The emitter and mirrors are in an opaque room which means light should not go out.
Where I am now is that I am able to draw the ray but when the angle is 90 degrees ( +or-) all the drawing disappears. I set some conditions to make up for this situation, but it does not seem to work.
Besides if the angle exceeds 90 degrees, the line is drawn in the opposite direction.
One other thing that happens is I set the ray to stop when either end_x_emitter_ray or end_y_emitter_ray = 500. It works for the end_x_emitter_ray but not for the end_y_emitter_ray
[end_x_emitter_ray and end_y_emitter_ray are the point where the ray end]

I have uploaded the my whole code here. Can you guys suggest me what can be done to make it work appropriately?
Thank you.
Ashaan.
Attached Files
File Type: zip Infrared simulation.zip (104.2 KB, 20 views)
__________________
You Get In Life What You Have
The Courage To Ask For!

Last edited by ashaan55; 01-06-2011 at 04:34 AM. Reason: Removed EXE/DLL from ZIP archive
Reply With Quote
  #2  
Old 01-06-2011, 05:20 AM
PlausiblyDamp's Avatar
PlausiblyDampSimulation Of a light Source and Mirrors...:) PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

I just had a quick skim of the code and I couldn't really locate where you detect a collision with a mirror.

Personally I wouldn't have spent 90 lines or so declaring all those mirror variables, it would make more sense to create a mirror class to encapsulate all the behaviour and the form could then contain a list of mirrors - this would also mean you could add or remove mirrors rather than be limited to a fixed number.

If I get chance I will try to throw together a quick example of what I mean.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 01-06-2011, 09:50 AM
ashaan55 ashaan55 is offline
Newcomer
 
Join Date: Nov 2010
Location: MU
Posts: 15
Default

I haven't yet included that part yet. But what I intend to do , since I already used equation to draw the ray, I would derive an equation for each mirror and I would solve them simultaneously to find if the point of intersection lies on the mirror. That would be kind of lenghty and there might be some problems too but I haven't thought of any better option yet and that's how I plan to proceed. Surely this might add some more variables in the list as well.
And I will be grateful if I could see an example of the mirror class. Thanks.
__________________
You Get In Life What You Have
The Courage To Ask For!
Reply With Quote
  #4  
Old 01-06-2011, 09:23 PM
ashaan55 ashaan55 is offline
Newcomer
 
Join Date: Nov 2010
Location: MU
Posts: 15
Default

In fact what I mostly wanted to know here is that when I keep on decrementing the angle by 5 degrees until the total angle decremented is about 90 degrees, all graphics disappears. [ At this instant, m_emitter, gradient of the ray, equals infinity.] I used some "if.. else" for that which does not seem to be very efficient. Besides, I also used a for loop which exits when the ray reaches the wall. If the ray reaches the lower horizontal wall, the ray does not stop, but continues. I welcome any suggestion. Thanks.
Ashaan.
__________________
You Get In Life What You Have
The Courage To Ask For!

Last edited by ashaan55; 01-07-2011 at 09:41 AM.
Reply With Quote
  #5  
Old 01-08-2011, 05:27 PM
passel's Avatar
passelSimulation Of a light Source and Mirrors...:) passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Set a breakpoint at the beginning of the function and step through the code and see if the calculated values are what you expect, and that the code branches in the manner you desire.
I can see you're trying to use slope equations to step the values, but I, in particular, don't have the time to try to go through all the code to identify problems. You should be testing the routines and equations as you develop them (called unit testing), rather than getting this far into the code, resulting in a lot more code to look at when trouble shooting.

But, a quick look, adding some Debug.Print statements to print out values and identify paths the code is taking, it looks like you have two blocks of code involved with generating the line, one when the line is going to the right, and the second when it is going to the left.
But, interestingly enough, if the line is going to the right, you increment X and if the line is going to the left, you increment X.

Incrementing X in both cases, moving left or right, doesn't seem right to me, but it could be if the calculation is just handing magnitude of the vector, and the direction was taken care of elsewhere.

So, again, I would suggest setting a break point, and then stepping through the code to verify the code is doing what you expect.
There are a lot of options with breakpoints, but most of the time I don't use them.
Basically I either set an unconditional breakpoint, to stop the code when ever it is hit.
Or, rather than set up a conditional breakpoint, just temporarily add a line of code that cause a "break" on a condition, such as:

If theta_emitter > 1.5 Then Stop

If theta_emitter is greater than 1.5 when that line is executed the code will stop executing and you will be in the IDE debugger and can then step through the code from that point.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #6  
Old 01-10-2011, 10:56 AM
ashaan55 ashaan55 is offline
Newcomer
 
Join Date: Nov 2010
Location: MU
Posts: 15
Cool

One thing that puzzles me here is that I set a condition for the for-loop to exit when the end_x_emitter_ray >= 50
Code:
For i = 0 To 550
                    end_x_emitter_ray += 1
                    end_y_emitter_ray = (m_emitter * end_x_emitter_ray) + c_emitter
                    If (end_y_emitter_ray >= 500 Or end_x_emitter_ray >= 500) Then
                        end_x_emitter_ray -= 1
                        end_y_emitter_ray = (m_emitter * end_x_emitter_ray) + c_emitter
                        Exit For
                    End If
                Next
I was observing the values and end_y_emitter reached values up to 2 million and still didn't exit the for loop. But it worked well as end_x-emitter never exceeded 500. It seems the for-loop is not obeying in this situation. I used stop too and the result is the same. Is there something wrong in the for-loop?
__________________
You Get In Life What You Have
The Courage To Ask For!

Last edited by ashaan55; 01-10-2011 at 11:14 AM.
Reply With Quote
  #7  
Old 01-18-2011, 08:26 PM
passel's Avatar
passelSimulation Of a light Source and Mirrors...:) passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

It always exited the for loop when I stepped through the code.
Of course, you're calculating end_y_emitter_ray, so it doesn't increment by 1, like the x direction does, so the y value can be less than 500 in one pass, and then 2 million in the next. You subtract 1 from end_x to bring it back into the box, but you don't make any adjustment to end_y to bring it back into the box.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply

Tags
aardvarks, angle, confused, disappears, light, rotate, vague tags


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:) Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
 
Simulation Of a light Source and Mirrors...:)
Simulation Of a light Source and Mirrors...:)
 
-->