joules 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.md +22 -0
- data/README.md +4 -1
- data/lib/joules/constants.rb +53 -49
- data/lib/joules/conversion.rb +65 -60
- data/lib/joules/density.rb +17 -12
- data/lib/joules/electric_fields.rb +69 -0
- data/lib/joules/electricity.rb +234 -227
- data/lib/joules/energy_work_power.rb +102 -99
- data/lib/joules/forces.rb +60 -55
- data/lib/joules/geometry.rb +117 -112
- data/lib/joules/gravitational_fields.rb +71 -0
- data/lib/joules/kinematics.rb +118 -113
- data/lib/joules/mass_weight.rb +24 -21
- data/lib/joules/momentum_impulse.rb +45 -40
- data/lib/joules/pressure.rb +28 -25
- data/lib/joules/quantum.rb +45 -42
- data/lib/joules/thermodynamics.rb +33 -28
- data/lib/joules/waves.rb +119 -116
- data/lib/joules.rb +3 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a84b8c006d8d0a2350bf289f2ed38840d872fb3
|
4
|
+
data.tar.gz: 26f4381a896f244a451e3582a1f190a423143fb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e95c4f6be852c8356a034f295a5e913187df2acc6437f887d2510eccfb539f69fcf228f5234f8f9990c7095f7a41aaaed1febdf403346fbaba92239c044f02d9
|
7
|
+
data.tar.gz: f6de041a305570a7e25f5544c6f61ea13afdf05cea7bf018eb8c984d80b395479159a583571cc382f4cb5e32686f2bbd55b8bc8e63b6c5d5dc0c22396530c515
|
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Elisha Lai
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ gem build joules.gemspec
|
|
15
15
|
|
16
16
|
### Library Installation
|
17
17
|
```Bash
|
18
|
-
gem install joules-0.3.
|
18
|
+
gem install joules-0.3.1.gem
|
19
19
|
```
|
20
20
|
|
21
21
|
### Library Import
|
@@ -60,6 +60,9 @@ This would return 23.4.
|
|
60
60
|
* Added Physics formulas in quantum
|
61
61
|
* Added more geometric and conversion formulas commonly used in Physics
|
62
62
|
|
63
|
+
#### Version 0.3.1
|
64
|
+
* Added Physics formulas in gravitational fields and electric fields
|
65
|
+
|
63
66
|
### Contribution
|
64
67
|
Please feel free to submit any ideas, questions, or problems by reporting an issue.
|
65
68
|
|
data/lib/joules/constants.rb
CHANGED
@@ -3,71 +3,75 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing constants
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Constants module (constants.rb)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
module Joules
|
12
|
+
|
13
|
+
# Speed of light in free space.
|
14
|
+
# @note This quantity is in meters per second.
|
15
|
+
SPEED_OF_LIGHT = 3.00e8
|
14
16
|
|
15
|
-
# Permeability of free space.
|
16
|
-
# @note This quantity is in henries per meter.
|
17
|
-
FREE_SPACE_PERMEABILITY = 4 * Math::PI * 1e-7
|
17
|
+
# Permeability of free space.
|
18
|
+
# @note This quantity is in henries per meter.
|
19
|
+
FREE_SPACE_PERMEABILITY = 4 * Math::PI * 1e-7
|
18
20
|
|
19
|
-
# Permittivity of free space.
|
20
|
-
# @note This quantity is in farads per meter.
|
21
|
-
FREE_SPACE_PERMITTIVITY = 8.85e-12
|
21
|
+
# Permittivity of free space.
|
22
|
+
# @note This quantity is in farads per meter.
|
23
|
+
FREE_SPACE_PERMITTIVITY = 8.85e-12
|
22
24
|
|
23
|
-
# Elementary charge.
|
24
|
-
# @note This quantity is in coulombs.
|
25
|
-
ELEMENTARY_CHARGE = 1.6e-19
|
25
|
+
# Elementary charge.
|
26
|
+
# @note This quantity is in coulombs.
|
27
|
+
ELEMENTARY_CHARGE = 1.6e-19
|
26
28
|
|
27
|
-
# Planck constant.
|
28
|
-
# @note This quantity is in joule seconds.
|
29
|
-
PLANCK_CONSTANT = 6.63e-34
|
29
|
+
# Planck constant.
|
30
|
+
# @note This quantity is in joule seconds.
|
31
|
+
PLANCK_CONSTANT = 6.63e-34
|
30
32
|
|
31
|
-
# Unified atomic mass unit.
|
32
|
-
# @note This quantiy is in kilograms.
|
33
|
-
UNIFIED_ATOMIC_MASS_UNIT = 1.66e-27
|
33
|
+
# Unified atomic mass unit.
|
34
|
+
# @note This quantiy is in kilograms.
|
35
|
+
UNIFIED_ATOMIC_MASS_UNIT = 1.66e-27
|
34
36
|
|
35
|
-
# Rest mass of electron.
|
36
|
-
# @note This quantity is in kilograms.
|
37
|
-
ELECTRON_MASS = 9.11e-31
|
37
|
+
# Rest mass of electron.
|
38
|
+
# @note This quantity is in kilograms.
|
39
|
+
ELECTRON_MASS = 9.11e-31
|
38
40
|
|
39
|
-
# Rest mass of proton.
|
40
|
-
# @note This quantity is in kilograms.
|
41
|
-
PROTON_MASS = 1.67e-27
|
41
|
+
# Rest mass of proton.
|
42
|
+
# @note This quantity is in kilograms.
|
43
|
+
PROTON_MASS = 1.67e-27
|
42
44
|
|
43
|
-
# Rest mass of neutron.
|
44
|
-
# @note This quantity is in kilograms.
|
45
|
-
NEUTRON_MASS = 1.67e-27
|
45
|
+
# Rest mass of neutron.
|
46
|
+
# @note This quantity is in kilograms.
|
47
|
+
NEUTRON_MASS = 1.67e-27
|
46
48
|
|
47
|
-
# Molar gas constant.
|
48
|
-
# @note This quantity is in joules per kelvin mole.
|
49
|
-
MOLAR_GAS_CONSTANT = 8.31
|
49
|
+
# Molar gas constant.
|
50
|
+
# @note This quantity is in joules per kelvin mole.
|
51
|
+
MOLAR_GAS_CONSTANT = 8.31
|
50
52
|
|
51
|
-
# Avogadro constant.
|
52
|
-
# @note This quantity is in per mole.
|
53
|
-
AVOGADRO_CONSTANT = 6.02e23
|
53
|
+
# Avogadro constant.
|
54
|
+
# @note This quantity is in per mole.
|
55
|
+
AVOGADRO_CONSTANT = 6.02e23
|
54
56
|
|
55
|
-
# Boltzmann constant.
|
56
|
-
# @note This quantity is in joules per kelvin.
|
57
|
-
BOLTZMANN_CONSTANT = 1.38e-23
|
57
|
+
# Boltzmann constant.
|
58
|
+
# @note This quantity is in joules per kelvin.
|
59
|
+
BOLTZMANN_CONSTANT = 1.38e-23
|
58
60
|
|
59
|
-
# Stefan constant.
|
60
|
-
# @note This quantity is in watts per meter squared kelvin to the fourth power.
|
61
|
-
STEFAN_CONSTANT = 5.67e-8
|
61
|
+
# Stefan constant.
|
62
|
+
# @note This quantity is in watts per meter squared kelvin to the fourth power.
|
63
|
+
STEFAN_CONSTANT = 5.67e-8
|
62
64
|
|
63
|
-
# Wien constant.
|
64
|
-
# @note This quantity is in meter kelvins.
|
65
|
-
WIEN_CONSTANT = 2.9e-3
|
65
|
+
# Wien constant.
|
66
|
+
# @note This quantity is in meter kelvins.
|
67
|
+
WIEN_CONSTANT = 2.9e-3
|
66
68
|
|
67
|
-
# Gravitational constant.
|
68
|
-
# @note This quantity is in newton metres squared per kilogram squared.
|
69
|
-
GRAVITATIONAL_CONSTANT = 6.67e-11
|
69
|
+
# Gravitational constant.
|
70
|
+
# @note This quantity is in newton metres squared per kilogram squared.
|
71
|
+
GRAVITATIONAL_CONSTANT = 6.67e-11
|
70
72
|
|
71
|
-
# Acceleration of free fall.
|
72
|
-
# @note This quantity is in meters per second squared.
|
73
|
-
FREE_FALL_ACCELERATION = 9.81
|
73
|
+
# Acceleration of free fall.
|
74
|
+
# @note This quantity is in meters per second squared.
|
75
|
+
FREE_FALL_ACCELERATION = 9.81
|
76
|
+
|
77
|
+
end
|
data/lib/joules/conversion.rb
CHANGED
@@ -3,73 +3,78 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing conversion formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Conversion module (conversion.rb)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
# angle is in radians
|
14
|
-
# @return [Float]
|
15
|
-
# return value is in degrees
|
16
|
-
# @example
|
17
|
-
# to_degrees(Math::PI/6) #=> 29.999999999999996
|
18
|
-
def to_degrees(angle)
|
19
|
-
return (angle * 180) / Math::PI
|
20
|
-
end
|
11
|
+
module Joules
|
12
|
+
module_function
|
21
13
|
|
22
|
-
# Calculates the equivalent angle in
|
23
|
-
# @param angle [Int, Float]
|
24
|
-
# angle is in
|
25
|
-
# @return [Float]
|
26
|
-
# return value is in
|
27
|
-
# @example
|
28
|
-
#
|
29
|
-
def
|
30
|
-
|
31
|
-
end
|
14
|
+
# Calculates the equivalent angle in degrees given radians.
|
15
|
+
# @param angle [Int, Float]
|
16
|
+
# angle is in radians
|
17
|
+
# @return [Float]
|
18
|
+
# return value is in degrees
|
19
|
+
# @example
|
20
|
+
# Joules.to_degrees(Math::PI/6) #=> 29.999999999999996
|
21
|
+
def to_degrees(angle)
|
22
|
+
return (angle * 180) / Math::PI
|
23
|
+
end
|
32
24
|
|
33
|
-
# Calculates the equivalent
|
34
|
-
# @param
|
35
|
-
#
|
36
|
-
# @return [Float]
|
37
|
-
# return value is in
|
38
|
-
# @example
|
39
|
-
#
|
40
|
-
def
|
41
|
-
|
42
|
-
end
|
25
|
+
# Calculates the equivalent angle in radians given degrees.
|
26
|
+
# @param angle [Int, Float]
|
27
|
+
# angle is in degrees
|
28
|
+
# @return [Float]
|
29
|
+
# return value is in radians
|
30
|
+
# @example
|
31
|
+
# Joules.to_radians(30) #=> 0.5235987755982988
|
32
|
+
def to_radians(angle)
|
33
|
+
return (angle * Math::PI) / 180
|
34
|
+
end
|
43
35
|
|
44
|
-
# Calculates the equivalent temperature in
|
45
|
-
# @param temperature [Int, Float]
|
46
|
-
# temperature is in
|
47
|
-
# @return [Float]
|
48
|
-
# return value is in
|
49
|
-
# @example
|
50
|
-
#
|
51
|
-
def
|
52
|
-
|
53
|
-
end
|
36
|
+
# Calculates the equivalent temperature in kelvins given celcius.
|
37
|
+
# @param temperature [Int, Float]
|
38
|
+
# temperature is in celcius
|
39
|
+
# @return [Float]
|
40
|
+
# return value is in kelvins
|
41
|
+
# @example
|
42
|
+
# Joules.to_kelvins(20) #=> 293.15
|
43
|
+
def to_kelvins(temperature)
|
44
|
+
return temperature + 273.15
|
45
|
+
end
|
54
46
|
|
55
|
-
# Calculates the equivalent
|
56
|
-
# @param
|
57
|
-
#
|
58
|
-
# @return [Float]
|
59
|
-
# return value is in
|
60
|
-
# @example
|
61
|
-
#
|
62
|
-
def
|
63
|
-
|
64
|
-
end
|
47
|
+
# Calculates the equivalent temperature in celcius given kelvins.
|
48
|
+
# @param temperature [Int, Float]
|
49
|
+
# temperature is in kelvins
|
50
|
+
# @return [Float]
|
51
|
+
# return value is in celcius
|
52
|
+
# @example
|
53
|
+
# Joules.to_celcius(293.15) #=> 20.0
|
54
|
+
def to_celcius(temperature)
|
55
|
+
return temperature - 273.15
|
56
|
+
end
|
57
|
+
|
58
|
+
# Calculates the equivalent velocity in meters per second given kilometers per hour.
|
59
|
+
# @param velocity [Int, Float]
|
60
|
+
# velocity is in kilometers per hour
|
61
|
+
# @return [Float]
|
62
|
+
# return value is in meters per second
|
63
|
+
# @example
|
64
|
+
# Joules.to_meters_per_second(200) #=> 55.55555555555556
|
65
|
+
def to_meters_per_second(velocity)
|
66
|
+
return (velocity * 1000) / 3600.0
|
67
|
+
end
|
68
|
+
|
69
|
+
# Calculates the equivalent velocity in kilometers per hour given meters per second.
|
70
|
+
# @param velocity [Int, Float]
|
71
|
+
# velocity is in meters per second
|
72
|
+
# @return [Float]
|
73
|
+
# return value is in kilometers per hour
|
74
|
+
# @example
|
75
|
+
# Joules.to_kilometers_per_hour(50) #=> 180.0
|
76
|
+
def to_kilometers_per_hour(velocity)
|
77
|
+
return (velocity * 3600) / 1000.0
|
78
|
+
end
|
65
79
|
|
66
|
-
# Calculates the equivalent velocity in kilometers per hour given meters per second.
|
67
|
-
# @param velocity [Int, Float]
|
68
|
-
# velocity is in meters per second
|
69
|
-
# @return [Float]
|
70
|
-
# return value is in kilometers per hour
|
71
|
-
# @example
|
72
|
-
# to_kilometers_per_hour(50) #=> 180.0
|
73
|
-
def to_kilometers_per_hour(velocity)
|
74
|
-
return (velocity * 3600) / 1000.0
|
75
80
|
end
|
data/lib/joules/density.rb
CHANGED
@@ -3,20 +3,25 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing density formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Density module (density.rb)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
|
21
|
-
|
11
|
+
module Joules
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Calculates the density given mass and volume.
|
15
|
+
# @param mass [Int, Float]
|
16
|
+
# mass >= 0; mass is in kilograms
|
17
|
+
# @param volume [Int, Float]
|
18
|
+
# volume > 0; volume is in meters cubed
|
19
|
+
# @return [Float]
|
20
|
+
# return value >= 0; return value is in kilograms per meter cubed
|
21
|
+
# @example
|
22
|
+
# Joules.density(8.96, 0.002) #=> 4480.0
|
23
|
+
def density(mass, volume)
|
24
|
+
return mass / volume.to_f
|
25
|
+
end
|
26
|
+
|
22
27
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing electric fields formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Electric fields module (electric_fields.rb)
|
10
|
+
|
11
|
+
module Joules
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Calculates the electric field strength given voltage and distance between two plates.
|
15
|
+
# @param voltage [Int, Float]
|
16
|
+
# voltage is in volts
|
17
|
+
# @param distance [Int, Float]
|
18
|
+
# distance > 0; distance is in meters
|
19
|
+
# @return [Float]
|
20
|
+
# return value is in newtons per coulomb/volts per metre
|
21
|
+
# @example
|
22
|
+
# Joules.electric_field_strength_v1(9, 0.1) #=> 90.0
|
23
|
+
# @note There are two other method for calculating electric field strength.
|
24
|
+
def electric_field_strength_v1(voltage, distance)
|
25
|
+
return voltage / distance.to_f
|
26
|
+
end
|
27
|
+
|
28
|
+
# Calculates the electric field strength for an uniform field given force and charge.
|
29
|
+
# @param force [Int, Float]
|
30
|
+
# force is in newtons
|
31
|
+
# @param charge [Int, Float]
|
32
|
+
# charge is in coulombs
|
33
|
+
# @return [Float]
|
34
|
+
# return value is in newtons per coulomb/volts per metre
|
35
|
+
# @example
|
36
|
+
# Joules.electric_field_strength_v2(50, 1.3e-6) #=> 38461538.461538464
|
37
|
+
# @note There are two other method for calculating electric field strength.
|
38
|
+
def electric_field_strength_v2(force, charge)
|
39
|
+
return force / charge.to_f
|
40
|
+
end
|
41
|
+
|
42
|
+
# Calculates the electric field strength for a radial field given charge and distance.
|
43
|
+
# @param charge [Int, Float]
|
44
|
+
# charge is in coulombs
|
45
|
+
# @param distance [Int, Float]
|
46
|
+
# distance > 0; distance is in meters
|
47
|
+
# @return [Float]
|
48
|
+
# return value is in newtons per coulomb/volts per metre
|
49
|
+
# @example
|
50
|
+
# Joules.electric_field_strength_v3(3.2e-19, 0.2) #=> 7.193443755565889e-08
|
51
|
+
# @note There are two other method for calculating electric field strength.
|
52
|
+
def electric_field_strength_v3(charge, distance)
|
53
|
+
return charge / (4 * Math::PI * FREE_SPACE_PERMITTIVITY * (distance ** 2))
|
54
|
+
end
|
55
|
+
|
56
|
+
# Calculates the electric potential given charge and distance.
|
57
|
+
# @param charge [Int, Float]
|
58
|
+
# charge is in coulombs
|
59
|
+
# @param distance [Int, Float]
|
60
|
+
# distance > 0; distance is in meters
|
61
|
+
# @return [Float]
|
62
|
+
# return value is in volts
|
63
|
+
# @example
|
64
|
+
# Joules.electric_potential(3.2e-19, 0.2) #=> 1.4386887511131779e-08
|
65
|
+
def electric_potential(charge, distance)
|
66
|
+
return charge / (4 * Math::PI * FREE_SPACE_PERMITTIVITY * distance)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|