Main Menu

Refletance Angles In 2D.

Started by ScottieB, January 30, 2014, 10:35:50 AM

Previous topic - Next topic

ScottieB

Here is what I'm thinking.

We have an input angle.
We check it against normal angle.
It's plus or minus the angle between.
It's switched over to other side or normal angle.
then it's incremented 180 degrees for the outcome.

Have a look at the 4 corners of the screen.
And see the pattern.

;45 To 0 = -45
;0 - 45 = 315
;315 + 180 = 135

; less than 90

;315 To 360 = 45
;0 + 45 = 45
;45 + 180 = 225

; greater than 270

;135 to 90 = -45
;90 - 45 = 45
;45 + 180 = 225

;45 to 90 = 45
;90 + 45 = 135
;135 + 180 = 315

;225 to 180 = -45
;180 - 45 = 135
;135 + 180 = 315

;135 to 180 = 45
;180 + 45 = 225
;225 + 180 = 45 with wraparound

; Instead of wrap around
; Greater than 180 minus
; Less than 180 add

; or 225 - 180 = 45

; 315 To 270 = -45
; 270 - 45 = 225
; 225 + 180 = 45
; or 225 - 180 = 45

; 225 to 270 = 45
; 270 + 45 = 315
; 315 + 180 = 135

; Instead of wraparound
; Greater than 180 minus
; Less than 180 add
; or 315 - 180 = 135

; Negative we minus angle
; Positive we add angle

Now.......................................

I think this will work to get the proper angle of reflectance.

But....................

Can anyone help me put this into a function?
The formulas above seem to be right.
I just want to simplify this nicely.
Thnks
ScottieB

kevin

#1
 
The reflect rays demo (from 2005) does this, you'll find it attached..

The Project Packs are on the downloads page if anybodies interested.  I highly recommend studying them very carefully ! 

ScottieB

Thanks!
Can you have a look at this code fragment.
It is giving me the right answer.  I pretty sure.
Can you see anything wrong or maybe an op?
I wish I could not use some of the functions of playbasic though so it can be ported.

Angle_1 = 45  ; Incident angle.
Surface_Angle = 90  ; Surface normal angle.

If Surface_Angle = 0 And Angle_1 < 90 Then Surface_Angle = 0
If Surface_Angle = 0 And Angle_1 > 270 Then Surface_Angle = 360

Angle_Difference = Surface_Angle - Angle_1  ; Half the angle between surface normal angle and incident angle.

If GetSign(Angle_Difference) = 1 Then Opposite_Angle = WrapValue(Surface_Angle - Abs(Angle_Difference),0,360)  ; Negative
If GetSign(Angle_Difference) = 0 Then Opposite_Angle = WrapValue(Surface_Angle + Abs(Angle_Difference),0,360)  ; Positive   

Reflectance_Angle = WrapValue(Opposite_Angle + 180,0,360)

Print "Incident_Angle = " + Str$(Angle_1)
Print "Angle_Difference = " + Str$(Angle_Difference)
Print "Reflectance_Angle = " + Str$(Reflectance_Angle)

Sync

WaitKey


kevin


QuoteI wish I could not use some of the functions of playbasic though so it can be ported.

then you're in the wrong place !