Angles (geometric), normalization and conversion: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: minor details)
m (→‎{{header|Haskell}}: fixed the zero representation)
Line 1,485: Line 1,485:
instance Show Rad where
instance Show Rad where
show (Rad 0) = printf "∠0"
show (Rad r) = printf "∠%.3f" r
show (Rad r) = printf "∠%.3f" r
Line 1,497: Line 1,498:
instance Show Deg where
instance Show Deg where
show (Deg d) = printf "%.3gº" d
show (Deg 0) = printf ""
show (Deg d) = printf "%.3g°" d
instance Angle Deg where
instance Angle Deg where
Line 1,509: Line 1,511:
instance Show Grad where
instance Show Grad where
show (Grad 0) = printf "0g"
show (Grad g) = printf "%.3gg" g
show (Grad g) = printf "%.3gg" g
Line 1,521: Line 1,524:
instance Show Mil where
instance Show Mil where
show (Mil 0) = printf "0m"
show (Mil m) = printf "%.3gm" m
show (Mil m) = printf "%.3gm" m
Line 1,527: Line 1,531:
mkAngle = Mil
mkAngle = Mil
value (Mil m) = m
value (Mil m) = m



-- example of non-linear angular unit
-- example of non-linear angular unit
Line 1,533: Line 1,538:
instance Show Slope where
instance Show Slope where
show (Slope m) = printf "%.g" (m * 100) ++ "%"
show (Slope 0) = printf "0%"
show (Slope m) = printf "%.g" (m * 100) ++ "%"
instance Angle Slope where
instance Angle Slope where
Line 1,546: Line 1,552:


<pre>λ> angle 45 :: Deg
<pre>λ> angle 45 :: Deg
45.000º
45.000°


λ> angle pi :: Rad
λ> angle pi :: Rad
Line 1,555: Line 1,561:


λ> normalize 450 :: Deg
λ> normalize 450 :: Deg
90.000º
90.000°


λ> normalize 450 :: Gon
λ> normalize 450 :: Gon
Line 1,575: Line 1,581:


λ> from @Gon @Deg (angle 100)
λ> from @Gon @Deg (angle 100)
90.000º
90.000°


λ> to @Gon (angle @Deg 45)
λ> to @Gon (angle @Deg 45)
Line 1,620: Line 1,626:
<pre>λ> main
<pre>λ> main
converting to radians
converting to radians
[∠-2.000,∠-1.000,∠0.000,∠1.000,∠2.000,∠6.283,∠3.434,∠0.747,∠0.858,∠3.159,∠2.717,∠5.926]
[∠-2.000,∠-1.000,∠0,∠1.000,∠2.000,∠6.283,∠3.434,∠0.747,∠0.858,∠3.159,∠2.717,∠5.926]
[∠-0.035,∠-0.017,∠0.000,∠0.017,∠0.035,∠0.110,∠0.279,∠1.000,∠6.266,∠0.681,∠4.869,∠4.887]
[∠-0.035,∠-0.017,∠0,∠0.017,∠0.035,∠0.110,∠0.279,∠1.000,∠6.266,∠0.681,∠4.869,∠4.887]
[∠-0.031,∠-0.016,∠0.000,∠0.016,∠0.031,∠0.099,∠0.251,∠0.900,∠5.639,∠6.267,∠6.267,∠0.000]
[∠-0.031,∠-0.016,∠0,∠0.016,∠0.031,∠0.099,∠0.251,∠0.900,∠5.639,∠6.267,∠6.267,∠0]
[∠-0.002,∠-0.001,∠0.000,∠0.001,∠0.002,∠0.006,∠0.016,∠0.056,∠0.352,∠0.392,∠6.282,∠1.571]
[∠-0.002,∠-0.001,∠0,∠0.001,∠0.002,∠0.006,∠0.016,∠0.056,∠0.352,∠0.392,∠6.282,∠1.571]
[∠-1.107,∠-0.785,∠0.000,∠0.785,∠1.107,∠1.413,∠1.508,∠1.553,∠1.568,∠1.568,∠1.571,∠1.571]
[∠-1.107,∠-0.785,∠0,∠0.785,∠1.107,∠1.413,∠1.508,∠1.553,∠1.568,∠1.568,∠1.571,∠1.571]


converting to degrees
converting to degrees
[-114.592º,-57.296º,0.000º,57.296º,114.592º,360.000º,196.732º,42.806º,49.185º,181.016º,155.693º,339.513º]
[-114.592°,-57.296°,0°,57.296°,114.592°,360.000°,196.732°,42.806°,49.185°,181.016°,155.693°,339.513°]
[-2.000º,-1.000º,0.000º,1.000º,2.000º,6.283º,16.000º,57.296º,359.000º,39.000º,279.000º,280.000º]
[-2.000°,-1.000°,0°,1.000°,2.000°,6.283°,16.000°,57.296°,359.000°,39.000°,279.000°,280.000°]
[-1.800º,-0.900º,0.000º,0.900º,1.800º,5.655º,14.400º,51.566º,323.100º,359.100º,359.100º,0.000º]
[-1.800°,-0.900°,0°,0.900°,1.800°,5.655°,14.400°,51.566°,323.100°,359.100°,359.100°,0°]
[-0.112º,-5.625e-2º,0.000º,5.625e-2º,0.112º,0.353º,0.900º,3.223º,20.194º,22.444º,359.944º,90.000º]
[-0.112°,-5.625e-2°,0°,5.625e-2°,0.112°,0.353°,0.900°,3.223°,20.194°,22.444°,359.944°,90.000°]
[-63.435º,-45.000º,0.000º,45.000º,63.435º,80.957º,86.424º,89.000º,89.840º,89.856º,89.991º,90.000º]
[-63.435°,-45.000°,0°,45.000°,63.435°,80.957°,86.424°,89.000°,89.840°,89.856°,89.991°,90.000°]


converting to grads
converting to grads
[-127.324g,-63.662g,0.000g,63.662g,127.324g,400.000g,218.592g,47.563g,54.650g,201.129g,172.992g,377.237g]
[-127.324g,-63.662g,0g,63.662g,127.324g,400.000g,218.592g,47.563g,54.650g,201.129g,172.992g,377.237g]
[-2.222g,-1.111g,0.000g,1.111g,2.222g,6.981g,17.778g,63.662g,398.889g,43.333g,310.000g,311.111g]
[-2.222g,-1.111g,0g,1.111g,2.222g,6.981g,17.778g,63.662g,398.889g,43.333g,310.000g,311.111g]
[-2.000g,-1.000g,0.000g,1.000g,2.000g,6.283g,16.000g,57.296g,359.000g,399.000g,399.000g,0.000g]
[-2.000g,-1.000g,0g,1.000g,2.000g,6.283g,16.000g,57.296g,359.000g,399.000g,399.000g,0g]
[-0.125g,-6.250e-2g,0.000g,6.250e-2g,0.125g,0.393g,1.000g,3.581g,22.438g,24.938g,399.938g,100.000g]
[-0.125g,-6.250e-2g,0g,6.250e-2g,0.125g,0.393g,1.000g,3.581g,22.438g,24.938g,399.938g,100.000g]
[-70.483g,-50.000g,0.000g,50.000g,70.483g,89.952g,96.026g,98.889g,99.823g,99.840g,99.990g,100.000g]
[-70.483g,-50.000g,0g,50.000g,70.483g,89.952g,96.026g,98.889g,99.823g,99.840g,99.990g,100.000g]


converting to mils
converting to mils
[-2037.183m,-1018.592m,0.000m,1018.592m,2037.183m,6400.000m,3497.466m,761.002m,874.397m,3218.063m,2767.877m,6035.788m]
[-2037.183m,-1018.592m,0m,1018.592m,2037.183m,6400.000m,3497.466m,761.002m,874.397m,3218.063m,2767.877m,6035.788m]
[-35.556m,-17.778m,0.000m,17.778m,35.556m,111.701m,284.444m,1018.592m,6382.222m,693.333m,4960.000m,4977.778m]
[-35.556m,-17.778m,0m,17.778m,35.556m,111.701m,284.444m,1018.592m,6382.222m,693.333m,4960.000m,4977.778m]
[-32.000m,-16.000m,0.000m,16.000m,32.000m,100.531m,256.000m,916.732m,5744.000m,6384.000m,6384.000m,0.000m]
[-32.000m,-16.000m,0m,16.000m,32.000m,100.531m,256.000m,916.732m,5744.000m,6384.000m,6384.000m,0m]
[-2.000m,-1.000m,0.000m,1.000m,2.000m,6.283m,16.000m,57.296m,359.000m,399.000m,6399.000m,1600.000m]
[-2.000m,-1.000m,0m,1.000m,2.000m,6.283m,16.000m,57.296m,359.000m,399.000m,6399.000m,1600.000m]
[-1127.732m,-800.000m,0.000m,800.000m,1127.732m,1439.234m,1536.421m,1582.224m,1597.163m,1597.447m,1599.841m,1599.999m]</pre>
[-1127.732m,-800.000m,0m,800.000m,1127.732m,1439.234m,1536.421m,1582.224m,1597.163m,1597.447m,1599.841m,1599.999m]</pre>


=={{header|J}}==
=={{header|J}}==