PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Phyisics, laws of refraction PLEASE HELP-VBForums
Results 1 to 6 of 6

Thread: Phyisics, laws of refraction PLEASE HELP

  1. #1

    Thread Starter
    Fanatic Member Alien_poo's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    668

    Phyisics, laws of refraction PLEASE HELP

    (SEE ATTACHED PROJECT) Ok, I have some light (the blue line on the right) coming through a substance, hitting another substance, and refracted at a certain angle (the blue line on the left). You enter the density of the second material in the text box, and choose the angle the light is hitting the second material (with the scroll-bar). Now the blue line on the left is suppose to move with the blue line on the right. Which is working... but not the right way! Proof: if you put the second material's density to 1, the light should NOT be refracted, but if you look at the blue line, when you come to an angle of 60 or so, it does start being refracted! And at an angle of like 65 the app gives me an error. PLEASE help me find what the problem is, I am getting desperate, this school project is for tomorrow.
    Attached Files Attached Files
    "A RESPECTED scientist has put forward the stunning - if unsavoury - possibility that humans are descended from sewage dumped overboard by aliens."
    "First we read that we are the creation of God, then scientists say we are descended from apes. Now they say we're some sort of alien poo. How much further can we sink?"
    - Robert Matthews, Science Correspondent

  2. #2
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174
    Well, the value you're getting for

    When dividing, the value in the denominator is:

    -2.75579550151111E-02

    Which I guess is too small, and producing a really large value to be squared.

  3. #3

    Thread Starter
    Fanatic Member Alien_poo's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    668
    how can I fix that?
    "A RESPECTED scientist has put forward the stunning - if unsavoury - possibility that humans are descended from sewage dumped overboard by aliens."
    "First we read that we are the creation of God, then scientists say we are descended from apes. Now they say we're some sort of alien poo. How much further can we sink?"
    - Robert Matthews, Science Correspondent

  4. #4
    ASP.NET Moderator mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174
    VB Code:
    1. Option Explicit
    2. Dim N2 As Single
    3. Dim AngleI As Integer
    4. Dim AngleR As Double
    5. Dim Reponse As Integer
    6. Dim X As Double
    7.  
    8. Private Sub Command1_Click()
    9.     End
    10. End Sub
    11.  
    12. Private Sub Command2_Click()
    13.     Text1.Text = ""
    14. End Sub
    15.  
    16. Private Sub HScroll1_Change()
    17.     If Val(Text1.Text) <= 0 Then
    18.         Reponse = MsgBox("Veuillez entrez un indice de refraction plus grand que 0", vbOKOnly + vbCritical, "Indice de refraction impossible")
    19.         Exit Sub
    20.     End If
    21.    
    22.     Line2.Visible = True
    23.     Line3.Visible = True
    24.     AngleI = HScroll1.Value
    25.     N2 = Val(Text1.Text)
    26.    
    27.     Line2.Y2 = 2000 - (1500 * Sin(AngleI * 3.141592 / 180))
    28.     Line2.X2 = 3000 + (1500 * Cos(AngleI * 3.141592 / 180))
    29.    
    30.     X = (AngleI * 3.14592 / 180) / N2
    31.     'AngleR = Atn(X / Sqr(-X * X + 1))
    32.     AngleR = ArcSin(X)
    33.    
    34.     Line3.Y2 = 2000 + (1500 * Sin(AngleR))
    35.     Line3.X2 = 3000 - (1500 * Cos(AngleR))
    36. End Sub
    37.  
    38. Function ArcSin(X As Double) As Double
    39.     X = CDbl(X)
    40.     'ArcSin = (Atn(X / Sqr(-X * X + 1)))
    41.     ArcSin = (Atn(X / ((-X * X + 1) * (-X * X + 1))))  '[b]I changed this[/b]
    42. End Function

    Is this acceptable?

  5. #5
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    Actually, it's being square-rooted

    It's producing a negative value which, of course, can't be square rooted without producing an imaginary number. Inverse tangent may actually be able to use imaginary numbers (I'm not sure on that, though), but VB doesn't like them. What is the formula you've been supplied with?

    Edit: It just hit me why that's not working: arcsin has a domain of -1 to 1 because that's the range of sin, so passing it a value of x greater than 1 or less than -1 will cause an error like that. Again, I'd have to see the formula to help.
    Last edited by jemidiah; Dec 12th, 2003 at 12:47 AM.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  6. #6
    Fanatic Member alkatran's Avatar
    Join Date
    Apr 2002
    Location
    Canada
    Posts
    860
    if I remember right, when you get an error when tryingto calculate that, it means the light was... absorbed, or travelling parrallel to the surface, or something like that... just use error checking
    Don't pay attention to this signature, it's contradictory.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width