Showing posts with label lighting. Show all posts
Showing posts with label lighting. Show all posts

Monday, August 5, 2019

TI-84 Plus CE and HP Prime: Calculating Color Temperature

TI-84 Plus CE and HP Prime:  Calculating Color Temperature

Introduction

We can estimate a color temperature for a given color.  However, the estimate is most useful when the color is close to white or the black body curve.  The color temperature, known as the CCT, is just one particular aspect of a color and its light quality. 

For more detailed information, please check the article by Waveform Lighting, https://www.waveformlighting.com/tech/calculate-color-temperature-cct-from-cie-1931-xy-coordinates.  The article will be listed in the Sources section at the end of this blog entry.

Calculation

The program RGBTEMP will estimate CCT from a color given its RGB (red-green-blue) coordinates. 

The calculation involves several steps:

1.  Scaling RGB values from a scale of 0-255 to 0-1.  This is accomplished by dividing each of the parameters of the color's RGB value by 255.  Standard RGB values (sRGB) are used. 

2.  The scaled RGB values will be converted to CIE 1931 XYZ color space values.  In 19031, the International Commission on Illumination created the CIE 1931 color space, designed to describe how the distribution of color wavelengths affect how colors are perceived.  The conversion is done in two parts.

2a.  Adjust each of the scaled RGB values to account for the gamma correction:

Let I be the scaled parameter for R, G, and B.  Then:

If I ≤ 0.04045, Then:

I_adj = I/12.92

Else:

I_adj = ( (I + 0.055) / 1.055) ^ 2.4

2b.  Calculate the XYZ values.   This can be accomplished by matrix multiplication:

[ [ X ] [ Y ] [ Z ] ] =

[[ 0.4124, 0.3576, 0.1805 ] [ 0.2126, 0.7152, 0.0722 ] [ 0.0193, 0.1192, 0.9504 ]]
*  [ [ R ] [ G ] [ B ] ]

3.  With the XYZ coordinates, calculate CIE Yxy coordinates.  Y is already done, so only (small) x and (small) y are needed:

x = X / (X + Y + Z)

y = Y / (X + Y + Z)

4.  Calculate the CCT.  There are several methods: one of them is a cubic approximation from Calvin McCamy:

n = (x - 0.3320) / (0.1858 - y)

CCT = 437 * n^3 + 3601 * n^2 + 6861 * n + 5517

CCT is in Kelvins.

TI-84 Plus Program RGBTEMP

"2019-07-11 EWS"
Disp "COLOR TEMP FROM RGB"
Input "RED   :",R
Input "GREEN :",G
Input "BLUE  :",B

[[R/255][G/255][B/255]]→[I]

For(I,1,3)
If [I](I,1)≤0.04045
Then
[I](I,1)/12.92→[I](I,1)
Else
(([I](I,1)+.055)/1.055)^2.4→[I](I,1)
End
End

[[.4124,.3576,.1805][.2126,.7152,.0722][.0193,.1192,.9504]]*[I]→[J]

[J](1,1)/([J](1,1)+[J](2,1)+[J](3,1))→X
[J](2,1)/([J](1,1)+[J](2,1)+[J](3,1))→Y

(X-.332)/(.1858-Y)→N
437*N^3+3601*N^2+6861*N+5517→C
Disp "CCT (K):",C

HP Prime Program RGBTEMP

The HP Prime version returns CCT, the XYZ coordinates, and the x and y parameters in a four element list.

EXPORT RGBTEMP(R,G,B)
BEGIN
// 2019-07-11 EWS
// RGB to color temperature
LOCAL M0,M1,X,Y,N,C;
LOCAL I,U,V,N,CCT;

// initialize
M0:=[[R/255],[G/255],[B/255]];

// correction
FOR I FROM 1 TO 3 DO
IF M0(I,1)≤0.04045 THEN
M0(I,1):=M0(I,1)/12.92;
ELSE
M0(I,1):=((M0(I,1)+0.055)
/1.055)^2.4;
END;
END;

// RGB to CIE XYZ 1931
M1:=[[0.4124,0.3576,0.1805],
[0.2126,0.7152,0.0722],
[0.0193,0.1192,0.9504]]*M0;

// XYZ to Yxy
X:=M1(1,1)/(M1(1,1)+M1(2,1)+
M1(3,1));
Y:=M1(2,1)/(M1(1,1)+M1(2,1)+
M1(3,1));

// xy to CCT (Kelvins)
// McCamy approximation
N:=(X-0.3320)/(.1858-Y);
C:=437*N^3+3601*N^2+6861*N+5517;

RETURN {C,M1,X,Y};

END;

Examples
(CCT rounded to four decimal places)

Remember the closer to the Black Body Curve, the more accurate the answer. 

Red:  RGB (255, 0, 0)
CCT:  3034.8988 K

Green:  RGB (0, 255, 0)
CCT:  6068.7576 K

Orange:  RGB (255, 165, 0)
CCT:  2429.5395 K

Sky Blue:  RGB (136, 206, 235)
CCT:  13207.1056 K

White:  RGB (255, 255, 255)
CCT:  6506.6551 K

Sources

"Convert color data into different standards and color spaces" and "Color math and programming code examples"   EASYRGB.  IRO Group Limited.  2019. https://www.easyrgb.com/en/convert.php  and https://www.easyrgb.com/en/math.php    Retrieved July 11, 2019

"Calculate color temperature (CCT) from CIE 1931 xy coordinates"  Waveform Lighting. 2019.  https://www.waveformlighting.com/tech/calculate-color-temperature-cct-from-cie-1931-xy-coordinates   Retrieved July 6, 2019

"sRGB"  Wikipedia.  Last edited May 18, 2019.  https://en.wikipedia.org/wiki/SRGB
Retrieved June 16, 2019.

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.

Monday, May 20, 2019

Intensity/Illumination, Days Since Jan. 1, Derivatives: HP 20S and 21S

Intensity/Illumination, Days Since Jan. 1, Derivatives: HP 20S and 21S

Table of contents

1.  Intensity and Illumination
2.  Days Since January 1
3.  Numerical Derivative

Disclaimer: I believe the key codes for the programs in this blog entry are the all the same even though the HP 20S and HP 21S have slightly different codes.  Format:   Step  Key: Key Code.  I took turns programming the HP 20S and HP 21S.

1.  Intensity and Illumination

The follow equation relates the luminous intensity (measured in candelas, cd) and illuminance (measured in lux) of a light source.  The equation assumes the light source radiates a spherical matter.

E = I / R^2

E = illuminance
I = luminous intensity
R = radius of the sphere's light (meters)

LBL A:  Solve for E
LBL B:  Solve for I
LBL C:  Solve for R

Registers:
R0 = E
R1 = I
R2 = R

Store the following values in the register and execute the appropriate label.

Program:

01  LBL A:  61,41,A
02 RCL 1:  22, 1
03 ÷:  45
04 RCL 2:  22, 2
05 x^2:  51, 11
06 =: 74
07 STO 0:  21, 0
08 R/S:  26
09 LBL B:  61,41,B
10  RCL 0: 22,0
11  *:  55
12  RCL 2: 22,2
13  x^2:  51,11
14  =:  74
15  STO 1: 21, 1
16  R/S:  26
17  LBL C: 61,41,C
18  RCL 1: 22,1
19 ÷: 45
20 RCL 0: 22,0
21  =:  74
22 √:  11
23 STO 2: 21, 2
24 R/S:  26

Example 1:
R1 = I = 400, R2 = R = 2.
Solve for E,  XEQ A returns 100

Example 2:
R0 = E = 180, R2 = R = 3
Solve for I, XEQ B returns 1620

Example 3:
R1 = I =420, R0 = E = 195
Solve for R, XEQ C returns 1.467598771

2.  Days Since January 1

Calculate the number of days since January 1.  For more information, please see:  http://edspi31415.blogspot.com/2019/03/ti-84-plus-and-hp-41c-number-of-days.html

Input:
R1:  day
R2: month
R3: 0 if we are working in a non-leap year, 1 if we are working in a leap year

Output:
R4:  number of days since January 1

Program:

01 LBL A: 61,41,A
02 RCL 1:  22,1
03 STO 4: 21, 4
04 3:  3
05 5:  5
06 STO - 4:  21,65,4
07 RCL 2: 22,2
08  INPUT:  31
09  2:  2
10  x ≤ y?:  61,42
11  GTO 2:  51,41,2
12  RCL 2: 22,2
13  *:  55
14  3:  3
15  0:  0
16  . : 73
17 6:  6
18  +:  75
19  1:  1
20  .  : 73
21  6:  6
22  =:  74
23  IP:  51, 45
24  STO + 4:  21,75,4
25  RCL 3:  22,3
26  STO + 4:  21,75,4
27  RCL 4: 22,4
28  RTN:  61, 26
29  LBL 2:  61,41,2
30  RCL 2:  22,2
31   *:  55
32  3:  3
33  0:  0
34  .  : 73
35  6:  6
36  +:  75
37  3:  3
38  6:  6
39  8:  8
40:  .  : 73
41  8:  8
42 =: 74
43  IP:  51,45
44  STO + 4:  21,75,4
45  3:  3
46  6:  6
47  5:  5
48  STO - 4:  21,65,4
49  RCL 4:  22,4
50  RTN:  61,26

Example 1:
1/1/2019 - 5/7/2019  (non-leap year)
R1:  7,  R2:  5,  R3:  0
Result:  R4 = 126

Example 2:
1/1/2020 - 11/14/2020  (leap year)
R1:  14,  R2:  11, R3:  1
Result:  R4 = 318

3.  Numerical Derivative

f'(x0) ≈ ( f(x0 + h) - f(x0 - h) ) / ( 2*h )

x = point
h = small change of x, example h = 0.0001

LBL A:  Main Progam
LBL F:  f(X), where R0 acts as X

Input variables:
R1 = h
R2 = point x0

Used variables:
R0 = x   (use R0 for f(x), LBL F)

Calculated Variables:
R3 = f'(x)

Radians mode will be set.

Program:

01  LBL A:  61,41A
02  RAD:  61,24
03  RCL 2:  22,2
04  +:  75
05  RCL 1:  22, 1
06  =:  74
07  STO 0:  21,0
08 XEQ F:  41,F
09  STO 3:  21, 3
10  RCL 2: 22,2
11 -:  65
12 RCL 1: 22,1
13 =:  74
14 STO 0: 21,0
15 XEQ F:  41,F
16 STO - 3:  21,65,3
17 2:  2
18 STO ÷ 3:  21,45,3
19  RCL 1:  22,1
20 STO ÷ 3: 21,45,3
21  RCL 3:  22,3
22 R/S:  26
23 LBL F:  61,41,F
...
xx  RTN:  61,26  (end f(X) with RTN)

Example:  e^x * sin x

LBL F
RCL 0
e^x
*
RCL 0
SIN 

RTN

R1 = 0.0001
R2 = x0 = 0.03
Result:  1.060899867

R1 = 0.0001
R2 = x0 = 1.47
Result:  4.7648049


Note:  I am going on vacation this week and I have jury duty in June. So far, I have blog entries scheduled to be posted throughout June 22.  I plan to have a weekly post every Saturday in June.  - E

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.

Monday, May 13, 2019

HP 42S/DM42/Free42: Room Cavity Ratio, Luminous Intensity and Illuminance

HP 42S/DM42/Free42:  Room Cavity Ratio, Luminous Intensity and Illuminance

Room Cavity Ratio



The room cavity ratio is used to assist in calculating lighting efficiency in determining where to place ceiling lights in an office room.  The formula is:

RCR = INT( ( 5 * H * ( L + W ) ) / ( L * W ) )

where:
L = length of the room
H = height difference between floor cavity and ceiling cavity
W = width of the room

HP 42S/DM42/Free42:  Solver RCR

LBL "RCR"
MVAR "H"
MVAR "L"
MVAR "W"
MVAR "RCR"
5
RCL * "H"
RCL "L"
RCL + "W"
*
RCL "L"
RCL * "W"
÷
IP
RCL - "RCR"
END

Examples

Example 1: 
Input:  H = 5.5, L = 16.8, W = 13.7.   Result:  RCR = 3

Example 2:
Input: H = 5.5, L = 16.8, RCR = 4.  Result:  H = 7.1650

Sources:

Dilouie, Craig.  "Lighting Design:  Example of Role Surfaces Play in Lighting Efficiency"  LightNOW  https://www.lightnowblog.com/2010/06/example-of-role-surfaces-play-in-lighting-efficiency/  June 16, 2010.  Retrieved March 31, 2019

"Room Cavity Ratio, RCR" Illuminating Engineering Society.  https://www.ies.org/definitions/room-cavity-ratio-rcr/  July 5, 2018.  Retrieved April 28, 2019

Luminous Intensity and Illuminance

The follow equation relates the luminous intensity (measured in candelas, cd) and illuminance (measured in lux) of a light source.  The equation assumes the light source radiates a spherical matter. 

E = I / R^2

E = illuminance
I = luminous intensity
R = radius of the sphere's light (meters)

HP 42S/DM42/Free42:  Solver ILSPH

LBL "ILSPH"
MVAR "E"
MVAR "I"
MVAR "R"
RCL "E"
RCL "I"
RCL "R"
x ↑ 2
÷
-
END

Examples

Example 1:
Input:  I = 10 cd, R = 2 m.  Result:  2.5 lux

Example 2:
Input:  R = 3.65 m, E = 30 lux.  Result:  I = 399.6750 cd

Sources:

Daryanani, Sital  Building Systems Design With Programmable Calculators Architectural Record Books.  McGraw-Hill Book Company: New York.  1980.  ISBN 0-07-015415-5

Zumtobel "The Lighting Handbook" Zumtobel Lighting GmbH.  Dornbirn, Austria.  6th Edition: 2018  https://www.zumtobel.com/PDB/Ressource/teaser/en/Lichthandbuch.pdf

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.

Monday, January 16, 2017

Retro Review: Halo HLC-1 Lighting Calculator

Retro Review:  Halo HLC-1 Lighting Calculator

HLC-1 Lighting Calculator
Years:  Unknown
Type:  4-Function, Lighting
Memory Registers: 1 (M)
Battery: A76

The Halo HCL-1 is a professional lighting calculator and a standard 4-function calculator. The standard 4-function calculator should be self-explanatory, let’s focus on the lighting part.

The HCL-1 is abundant on eBay, and make sure you get it with the foldout manual because (1) the manual is well written and (2) it explains the process in which pre-programmed calculations are completed.  I will show a short summary of some of the pre-calculations available below.

Trig table from the manual, something we don't see in calculator manuals

Did I mention that the manual contains a short table of sines and cosines?

US units are used (length is measured in feet).

Calculating Room Cavity Ratio:

Input:
Room Width in feet, [ RW ]
Rood Length in feet, [ RL ]
Room Cavity Height in feet, [ H ]

Output:
[ RCR ] calculates the Room Cavity Ratio

The HCL-1 assumes a rectangular room.  The formula:

RCR = (5 * H * (RW + RL)) / (RW * RL)

Footcandle Calculation

Input:
Coefficient of Utilization, between 0 and 1, [ CU ]
Number of lamp lumens, [ LL ]
Required footcandles, [ FC ]

Output:
Press [ CAL ].  If successful, a 0 appears in the display.
[ RCL ] [ NUM ]:  number of adjusted luminaries (lights)
[ RCL ] [ FC ]:  number of adjusted footcandles
[ RCL ] [ A ]:  area that is illuminated
[ RCL ] [ SPG ]:  fixture spacing in feet

I am thinking that this solves where to put ceiling lights on the ceiling in a grid, like in a school classroom or business office.

You can factor in the lamp lumen depreciation factor ( [ LLD ] ) AND luminaire dirt deprecation factor ( [ LDD ] ).

Final Verdict

I am glad to have the HLC 1 in my collection.  It is one of the most unique calculators ever made and was met with amusement when I posted a picture of it on my Instagram account.  Don’t lose the manual. 

Eddie

This blog is property of Edward Shore, 2017

RPN: DM32 and DM42: Stopping Sight Distance (Metric)

RPN: DM32 and DM42: Stopping Sight Distance (Metric) The Stopping Sight Distance Formula – Derivation The stopping sight di...