Saturday, October 12, 2019

HP Prime: Law of Refraction

HP Prime: Law of Refraction 

Introduction

The program DRAWREFRACT, visually demonstrates the Law of Refraction, or Snell's Law:

n1 sin θi = n2 sin θt

The program asks for n1, θi, and n2; and calculates θt.  The program draws the incident ray (in red) and the refracted ray (in blue).  The calculator is set to Degrees mode and the Function app. 

Note: you can find the angle character ∡, by pressing [SHIFT] [ × ]. 

HP Prime: Law of Refraction: DRAWREFRACT

Program:
EXPORT DRAWREFRACT(n1,θ1,n2)
BEGIN
// EWS 2018-08-20
// drawing Descates law
HAngle:=1; // Degrees
LOCAL θ2,x1,y1,x2,y2;
LOCAL str1,str2;
// window setup
STARTAPP("Function");
STARTVIEW(11,0);  // Decimal zoom
// calculation
θ2:=ASIN(n1*SIN(θ1)/n2);
x1:=RE(16∡(θ1+90));
y1:=IM(16∡(θ1+90));
x2:=RE(16∡(270+θ2));
y2:=IM(16∡(270+θ2));
// plot
RECT();
// draw axis
LINE(0,−16,0,16,0);
LINE(16,0,−16,0,0);
// draw analysis
LINE(0,0,x1,y1,#FF0000h);
LINE(0,0,x2,y2,#0000FFh);
str1:="n = "+STRING(n1)+
", θi = "+STRING(θ1);
str2:="-> n = "+STRING(n2)+
", θt = "+STRING(θ2);
TEXTOUT(str1,−15,−5,4,#FF0000h);
TEXTOUT(str2,−15,−8,4,#0000FFh);
WAIT(0);
// display home
STARTVIEW(−1);
END;

Example

n1 = 1.001
θ = 34.5°
n2= 1.205

DRAWREFRACT(1.001, 34.5, 1.205)

Result:
θt = 28.0678429359°



Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.