joules 0.1.0 → 0.2.0
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/lib/joules/constants.rb +1 -1
- data/lib/joules/conversion.rb +75 -0
- data/lib/joules/density.rb +2 -2
- data/lib/joules/electricity.rb +215 -0
- data/lib/joules/energy_work_power.rb +11 -10
- data/lib/joules/forces.rb +5 -5
- data/lib/joules/geometry.rb +92 -0
- data/lib/joules/kinematics.rb +9 -9
- data/lib/joules/mass_weight.rb +3 -3
- data/lib/joules/momentum_impulse.rb +4 -4
- data/lib/joules/pressure.rb +3 -3
- data/lib/joules/thermodynamics.rb +5 -5
- data/lib/joules/waves.rb +33 -6
- data/lib/joules.rb +4 -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: fe0112745ba13a5455d979a35367768cdaa2f382
|
4
|
+
data.tar.gz: eca09701308ea046cf92d8a6b2777af12d4011b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc5a94a2b8b9c9674d971c556335fb1ab4ccd116f2e95fe29c56f501d6b7daf89c7157a5cb1d38406d24c5cd71c1a359e9da3cdb6ec006283d99d73b6312520a
|
7
|
+
data.tar.gz: dea84c2a922ef20939c23216253bdaf0370e4b693609fb838f12c7f4260adc7517a594772134c74fcd9a66fb59d1abe916d6d00bea06c56d16964e83a843d32b
|
data/lib/joules/constants.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing conversion formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Conversion module (conversion.rb)
|
10
|
+
|
11
|
+
# Calculates the equivalent angle in degrees given radians.
|
12
|
+
# @param angle [Int, Float]
|
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
|
21
|
+
|
22
|
+
# Calculates the equivalent angle in radians given degrees.
|
23
|
+
# @param angle [Int, Float]
|
24
|
+
# angle is in degrees
|
25
|
+
# @return [Float]
|
26
|
+
# return value is in radians
|
27
|
+
# @example
|
28
|
+
# to_radians(30) #=> 0.5235987755982988
|
29
|
+
def to_radians(angle)
|
30
|
+
return (angle * Math::PI) / 180
|
31
|
+
end
|
32
|
+
|
33
|
+
# Calculates the equivalent temperature in kelvins given celcius.
|
34
|
+
# @param temperature [Int, Float]
|
35
|
+
# temperature is in celcius
|
36
|
+
# @return [Float]
|
37
|
+
# return value is in kelvins
|
38
|
+
# @example
|
39
|
+
# to_kelvins(20) #=> 293.15
|
40
|
+
def to_kelvins(temperature)
|
41
|
+
return temperature + 273.15
|
42
|
+
end
|
43
|
+
|
44
|
+
# Calculates the equivalent temperature in celcius given kelvins.
|
45
|
+
# @param temperature [Int, Float]
|
46
|
+
# temperature is in kelvins
|
47
|
+
# @return [Float]
|
48
|
+
# return value is in celcius
|
49
|
+
# @example
|
50
|
+
# to_celcius(293.15) #=> 20.0
|
51
|
+
def to_celcius(temperature)
|
52
|
+
return temperature - 273.15
|
53
|
+
end
|
54
|
+
|
55
|
+
# Calculates the equivalent velocity in meters per second given kilometers per hour.
|
56
|
+
# @param velocity [Int, Float]
|
57
|
+
# velocity is in kilometers per hour
|
58
|
+
# @return [Float]
|
59
|
+
# return value is in meters per second
|
60
|
+
# @example
|
61
|
+
# to_meters_per_second(200) #=> 55.55555555555556
|
62
|
+
def to_meters_per_second(velocity)
|
63
|
+
return (velocity * 1000) / 3600.0
|
64
|
+
end
|
65
|
+
|
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
|
+
end
|
data/lib/joules/density.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing density formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Density module (density.rb)
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# @param volume [Int, Float]
|
15
15
|
# volume > 0; volume is in meters cubed
|
16
16
|
# @return [Float]
|
17
|
-
#
|
17
|
+
# return value >= 0; return value is in kilograms per meter cubed
|
18
18
|
# @example
|
19
19
|
# density(8.96, 0.002) #=> 4480.0
|
20
20
|
def density(mass, volume)
|
@@ -0,0 +1,215 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing electricity formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Electricity module (electricity.rb)
|
10
|
+
|
11
|
+
# Calculates the current given charge and time.
|
12
|
+
# @param charge [Int, Float]
|
13
|
+
# charge is in coulombs
|
14
|
+
# @param time [Int, Float]
|
15
|
+
# time > 0; time is in seconds
|
16
|
+
# @return [Float]
|
17
|
+
# return value is in amperes
|
18
|
+
# @example
|
19
|
+
# current(325, 5) #=> 65.0
|
20
|
+
def current(charge, time)
|
21
|
+
return charge / time.to_f
|
22
|
+
end
|
23
|
+
|
24
|
+
# Calculates the resistance given voltage and current.
|
25
|
+
# @param voltage [Int, Float]
|
26
|
+
# voltage is in volts
|
27
|
+
# @param current [Int, Float]
|
28
|
+
# current != 0; current is in amperes
|
29
|
+
# @return [Float]
|
30
|
+
# return value is in ohms
|
31
|
+
# @example
|
32
|
+
# resistance(1.8, 0.6) #=> 3.0
|
33
|
+
# @note There is one other method for calculating resistance.
|
34
|
+
def resistance_v1(voltage, current)
|
35
|
+
return voltage / current.to_f
|
36
|
+
end
|
37
|
+
|
38
|
+
# Calculates the resistance given resistivity, wire length, and cross sectional area.
|
39
|
+
# @param resistivity [Int, Float]
|
40
|
+
# resistivity >= 0; resistivity is in ohm metres
|
41
|
+
# @param wire_length [Int, Float]
|
42
|
+
# wire_length >= 0; wire_length is in meters
|
43
|
+
# @param cross_sectional_area [Int, Float]
|
44
|
+
# cross_sectional_area > 0; cross_sectional_area is in meters squared
|
45
|
+
# @return [Float]
|
46
|
+
# return value >= 0; return value is in ohms
|
47
|
+
# @example
|
48
|
+
# resistance_v2(1e13, 250, 0.4) #=> 6.25e+15
|
49
|
+
# @note There is one other method for calculating resistance.
|
50
|
+
def resistance_v2(resistivity, wire_length, cross_sectional_area)
|
51
|
+
return (resistivity * wire_length) / cross_sectional_area.to_f
|
52
|
+
end
|
53
|
+
|
54
|
+
# Calculates the total resistance of resistors in series.
|
55
|
+
# @param resistances [Array<Int, Float>]
|
56
|
+
# each resistance in resistances is in ohms
|
57
|
+
# @return [Float]
|
58
|
+
# return value is in ohms
|
59
|
+
# @example
|
60
|
+
# resistance_in_series([10, 5, 3.4, 6.3]) #=> 24.7
|
61
|
+
def resistance_in_series(resistances)
|
62
|
+
total_resistance = 0
|
63
|
+
resistances.each do |resistance|
|
64
|
+
total_resistance += resistance
|
65
|
+
end
|
66
|
+
return total_resistance.to_f
|
67
|
+
end
|
68
|
+
|
69
|
+
# Calculates the total resistance of resistors in parallel.
|
70
|
+
# @param resistances [Array<Int, Float>]
|
71
|
+
# each resistance in resistances != 0; each resistance in resistances is in ohms
|
72
|
+
# @return [Float]
|
73
|
+
# return value is in ohms
|
74
|
+
# @example
|
75
|
+
# resistance_in_parallel([0.5, 0.25, 0.125]) #=> 0.07142857142857142
|
76
|
+
def resistance_in_parallel(resistances)
|
77
|
+
if resistances.empty?
|
78
|
+
raise ArgumentError.new('empty list of resistances')
|
79
|
+
end
|
80
|
+
total_resistance = 0
|
81
|
+
resistances.each do |resistance|
|
82
|
+
total_resistance += (1.0 / resistance)
|
83
|
+
end
|
84
|
+
return 1 / total_resistance
|
85
|
+
end
|
86
|
+
|
87
|
+
# Calculates the total capacitance given charge and voltage.
|
88
|
+
# @param charge [Int, Float]
|
89
|
+
# charge is in coulombs
|
90
|
+
# @param voltage [Int, Float]
|
91
|
+
# voltage != 0; voltage is in volts
|
92
|
+
# @return [Float]
|
93
|
+
# return value is in farads
|
94
|
+
def capacitance(charge, voltage)
|
95
|
+
return charge / voltage.to_f
|
96
|
+
end
|
97
|
+
|
98
|
+
# Calculates the total capacitance of capacitors in series.
|
99
|
+
# @param capacitances [Array<Int, Float>]
|
100
|
+
# each capacitance in resistances != 0; each capacitance in capacitances is in farads
|
101
|
+
# @return [Float]
|
102
|
+
# return value is in farads
|
103
|
+
# @example
|
104
|
+
# capacitance_in_series([0.5, 0.25, 0.125]) #=> 0.07142857142857142
|
105
|
+
def capacitance_in_series(capacitances)
|
106
|
+
if capacitances.empty?
|
107
|
+
raise ArgumentError.new('empty list of capacitances')
|
108
|
+
end
|
109
|
+
total_capacitance = 0
|
110
|
+
capacitances.each do |capacitance|
|
111
|
+
total_capacitance += (1.0 / capacitance)
|
112
|
+
end
|
113
|
+
return 1 / total_capacitance
|
114
|
+
end
|
115
|
+
|
116
|
+
# Calculates the total capacitance in parallel given capacitances.
|
117
|
+
# @param capacitances [Array<Int, Float>]
|
118
|
+
# each capacitance in capacitances is in farads
|
119
|
+
# @return [Float]
|
120
|
+
# return value is in farads
|
121
|
+
# @example
|
122
|
+
# capacitance_in_parallel([10, 5, 3.4, 6.3]) #=> 24.7
|
123
|
+
def capacitance_in_parallel(capacitances)
|
124
|
+
total_capacitance = 0
|
125
|
+
capacitances.each do |capacitance|
|
126
|
+
total_capacitance += capacitance
|
127
|
+
end
|
128
|
+
return total_capacitance.to_f
|
129
|
+
end
|
130
|
+
|
131
|
+
# Calculates the voltage given energy and charge.
|
132
|
+
# @param energy [Int, Float]
|
133
|
+
# energy is in joules
|
134
|
+
# @param charge [Int, Float]
|
135
|
+
# charge != 0; charge is in coulombs
|
136
|
+
# @return [Float]
|
137
|
+
# return value is in volts
|
138
|
+
# @example
|
139
|
+
# voltage_v1(1.8, 0.6) #=> 3.0
|
140
|
+
# @note There is one other method for calculating voltage.
|
141
|
+
def voltage_v1(energy, charge)
|
142
|
+
return energy / charge.to_f
|
143
|
+
end
|
144
|
+
|
145
|
+
# Calculates the voltage given current and resistance.
|
146
|
+
# @param current [Int, Float]
|
147
|
+
# current is in amperes
|
148
|
+
# @param resistance [Int, Float]
|
149
|
+
# resistance is in ohms
|
150
|
+
# @return [Float]
|
151
|
+
# return value is in volts
|
152
|
+
# @example
|
153
|
+
# voltage_v2(0.6, 3) #=> 1.8
|
154
|
+
# @note There is one other method for calculating voltage.
|
155
|
+
def voltage_v2(current, resistance)
|
156
|
+
return current * resistance.to_f
|
157
|
+
end
|
158
|
+
|
159
|
+
# Calculates the power given voltage and current.
|
160
|
+
# @param voltage [Int, Float]
|
161
|
+
# voltage is in volts
|
162
|
+
# @param current [Int, Float]
|
163
|
+
# current is in amperes
|
164
|
+
# @return [Float]
|
165
|
+
# return value is in watts
|
166
|
+
# @example
|
167
|
+
# power_v2(1.8, 0.6) #=> 1.08
|
168
|
+
# @note There are three other methods for calculating power.
|
169
|
+
def power_v2(voltage, current)
|
170
|
+
return voltage * current.to_f
|
171
|
+
end
|
172
|
+
|
173
|
+
# Calculates the power given current and resistance.
|
174
|
+
# @param current [Int, Float]
|
175
|
+
# current is in amperes
|
176
|
+
# @param resistance [Int, Float]
|
177
|
+
# resistance is in ohms
|
178
|
+
# @return [Float]
|
179
|
+
# return value is in watts
|
180
|
+
# @example
|
181
|
+
# power_v3(0.6, 3) #=> 1.08
|
182
|
+
# @note There are three other methods for calculating power.
|
183
|
+
def power_v3(current, resistance)
|
184
|
+
return (current ** 2.0) * resistance
|
185
|
+
end
|
186
|
+
|
187
|
+
# Calculates the power given voltage and resistance.
|
188
|
+
# @param voltage [Int, Float]
|
189
|
+
# voltage is in volts
|
190
|
+
# @param resistance [Int, Float]
|
191
|
+
# resistance != 0; resistance is in ohms
|
192
|
+
# @return [Float]
|
193
|
+
# return value is in watts
|
194
|
+
# @example
|
195
|
+
# power_v4(1.8, 3) #=> 1.08
|
196
|
+
# @note There are three other methods for calculating power.
|
197
|
+
def power_v4(voltage, resistance)
|
198
|
+
return (voltage ** 2.0) / resistance
|
199
|
+
end
|
200
|
+
|
201
|
+
# Calculates the energy given voltage, current, and time.
|
202
|
+
# @param voltage [Int, Float]
|
203
|
+
# voltage is in volts
|
204
|
+
# @param current [Int, Float]
|
205
|
+
# current is in amperes
|
206
|
+
# @param time [Int, Float]
|
207
|
+
# time >= 0; time is in seconds
|
208
|
+
# @return [Float]
|
209
|
+
# return value is in joules
|
210
|
+
# @example
|
211
|
+
# energy_v3(1.8, 0.6, 5) #=> 5.4
|
212
|
+
# @note There are two other methods for calculating energy.
|
213
|
+
def energy_v3(voltage, current, time)
|
214
|
+
return power_v2(voltage, current) * time
|
215
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing energy, work, and power formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Energy, work, and power module (energy_work_power.rb)
|
@@ -16,7 +16,7 @@ require_relative 'constants'
|
|
16
16
|
# @param height [Int, Float]
|
17
17
|
# height >= 0; height is in meters
|
18
18
|
# @return [Float]
|
19
|
-
#
|
19
|
+
# return value >= 0; return value is in joules
|
20
20
|
# @example
|
21
21
|
# gravitational_potential_energy(0.5, 6) #=> 29.43
|
22
22
|
def gravitational_potential_energy(mass, height)
|
@@ -29,7 +29,7 @@ end
|
|
29
29
|
# @param extension [Int, Float]
|
30
30
|
# extension >= 0; extension is in meters
|
31
31
|
# @return [Float]
|
32
|
-
#
|
32
|
+
# return value >= 0; return value is in joules
|
33
33
|
# @example
|
34
34
|
# elastic_potential_energy(81.75, 2.4) #=> 235.44
|
35
35
|
def elastic_potential_energy(spring_constant, extension)
|
@@ -42,7 +42,7 @@ end
|
|
42
42
|
# @param velocity [Int, Float]
|
43
43
|
# velocity is in meters per second
|
44
44
|
# @return [Float]
|
45
|
-
#
|
45
|
+
# return value >= 0; return value is in joules
|
46
46
|
# @example
|
47
47
|
# kinetic_energy(500, 22) #=> 121000.0
|
48
48
|
def kinetic_energy(mass, velocity)
|
@@ -55,7 +55,7 @@ end
|
|
55
55
|
# @param distance [Int, Float]
|
56
56
|
# distance >= 0; distance is in meters
|
57
57
|
# @return [Float]
|
58
|
-
#
|
58
|
+
# return value is in joules
|
59
59
|
# @example
|
60
60
|
# work_done(40, 2.34) #=> 93.6
|
61
61
|
def work_done(force, distance)
|
@@ -68,10 +68,11 @@ end
|
|
68
68
|
# @param time [Int, Float]
|
69
69
|
# time > 0; time is in seconds
|
70
70
|
# @return [Float]
|
71
|
-
#
|
71
|
+
# return value is in watts
|
72
72
|
# @example
|
73
|
-
#
|
74
|
-
|
73
|
+
# power_v1(28, 7) #=> 4.0
|
74
|
+
# @note There are three other methods for calculating power.
|
75
|
+
def power_v1(work_done, time)
|
75
76
|
return work_done / time.to_f
|
76
77
|
end
|
77
78
|
|
@@ -81,7 +82,7 @@ end
|
|
81
82
|
# @param energy_input [Int, Float]
|
82
83
|
# energy_input > 0; energy_input is in joules
|
83
84
|
# @return [Float]
|
84
|
-
#
|
85
|
+
# return value >= 0
|
85
86
|
# @example
|
86
87
|
# energy_efficiency(16, 20) #=> 80.0
|
87
88
|
def energy_efficiency(useful_energy_output, energy_input)
|
@@ -94,7 +95,7 @@ end
|
|
94
95
|
# @param power_input [Int, Float]
|
95
96
|
# power_input > 0; power_input is in watts
|
96
97
|
# @return [Float]
|
97
|
-
#
|
98
|
+
# return value >= 0
|
98
99
|
# @example
|
99
100
|
# power_efficiency(26, 40) #=> 65.0
|
100
101
|
def power_efficiency(useful_power_output, power_input)
|
data/lib/joules/forces.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing forces formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Forces module (forces.rb)
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# @param acceleration [Int, Float]
|
15
15
|
# acceleration is in meters per second squared
|
16
16
|
# @return [Float]
|
17
|
-
#
|
17
|
+
# return value is in newtons
|
18
18
|
# @example
|
19
19
|
# force_v1(120, 2.67) #=> 320.4
|
20
20
|
# @note There are two other methods for calculating force.
|
@@ -28,7 +28,7 @@ end
|
|
28
28
|
# @param extension [Int, Float]
|
29
29
|
# extension >= 0; extension is in meters
|
30
30
|
# @return [Float]
|
31
|
-
#
|
31
|
+
# return value >= 0; return value is in newtons
|
32
32
|
# @example
|
33
33
|
# force_v2(81.75, 2.4) #=> 196.2
|
34
34
|
# @note There are two other methods for calculating force.
|
@@ -46,7 +46,7 @@ end
|
|
46
46
|
# @param time [Int, Float]
|
47
47
|
# time > 0; time is in seconds
|
48
48
|
# @return [Float]
|
49
|
-
#
|
49
|
+
# return value is in newtons
|
50
50
|
# @example
|
51
51
|
# force_v3(20, 35, 50, 2.4) #=> 312.5
|
52
52
|
# @note There are two other methods for calculating force.
|
@@ -60,7 +60,7 @@ end
|
|
60
60
|
# @param distance [Int, Float]
|
61
61
|
# distance >= 0; distance is in meters
|
62
62
|
# @return [Float]
|
63
|
-
#
|
63
|
+
# return value is in newton metres
|
64
64
|
# @example
|
65
65
|
# moment(23, 4.5) #=> 103.5
|
66
66
|
def moment(force, distance)
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing geometry formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Geometry module (geometry.rb)
|
10
|
+
|
11
|
+
# Calculates the arc length of a circle given radius and central angle.
|
12
|
+
# @param radius [Int, Float]
|
13
|
+
# radius >= 0; radius is in a unit of length
|
14
|
+
# @param central_angle [Int, Float]
|
15
|
+
# central_angle >= 0; central_angle is in radians
|
16
|
+
# @return [Float]
|
17
|
+
# return value >= 0; return value has the same units as radius
|
18
|
+
# @example
|
19
|
+
# arc_length(12, (Math::PI/4)) #=> 9.42477796076938
|
20
|
+
def arc_length(radius, central_angle)
|
21
|
+
return radius * central_angle.to_f
|
22
|
+
end
|
23
|
+
|
24
|
+
# Calculates the circumference of a circle given radius.
|
25
|
+
# @param radius [Int, Float]
|
26
|
+
# radius >= 0; radius is in a unit of length
|
27
|
+
# @return [Float]
|
28
|
+
# return value >= 0; return value has the same units as radius
|
29
|
+
# @example
|
30
|
+
# circumference(12) #=> 75.398223686155
|
31
|
+
def circumference(radius)
|
32
|
+
return 2 * Math::PI * radius
|
33
|
+
end
|
34
|
+
|
35
|
+
# Calculates the area of a circle given radius.
|
36
|
+
# @param radius [Int, Float]
|
37
|
+
# radius >= 0; radius is in a unit of length
|
38
|
+
# @return [Float]
|
39
|
+
# return value >= 0; return value has the same units as radius
|
40
|
+
# @example
|
41
|
+
# circle_area(12) #=> 452.38934211693
|
42
|
+
def circle_area(radius)
|
43
|
+
return Math::PI * (radius ** 2)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Calculates the surface area of a sphere given radius.
|
47
|
+
# @param radius [Int, Float]
|
48
|
+
# radius >= 0; radius is in a unit of length
|
49
|
+
# @return [Float]
|
50
|
+
# return value >= 0; return value has the same units as radius
|
51
|
+
# @example
|
52
|
+
# sphere_surface_area(12) #=> 1809.55736846772
|
53
|
+
def sphere_surface_area(radius)
|
54
|
+
return 4 * Math::PI * (radius ** 2)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Calculates the volume of a sphere given radius.
|
58
|
+
# @param radius [Int, Float]
|
59
|
+
# radius >= 0; radius is in a unit of length
|
60
|
+
# @return [Float]
|
61
|
+
# return value >= 0; return value has the same units as radius
|
62
|
+
# @example
|
63
|
+
# sphere_volume(12) #=> 7238.22947387088
|
64
|
+
def sphere_volume(radius)
|
65
|
+
return (4 * Math::PI * (radius ** 3)) / 3
|
66
|
+
end
|
67
|
+
|
68
|
+
# Calulates the surface area of a cylinder given radius and height.
|
69
|
+
# @param radius [Int, Float]
|
70
|
+
# radius >= 0; radius is in a unit of length
|
71
|
+
# @param height [Int, Float]
|
72
|
+
# height >= 0; height has the same units as radius
|
73
|
+
# @return [Float]
|
74
|
+
# return value >= 0; return value has the same units as radius
|
75
|
+
# @example
|
76
|
+
# cylinder_surface_area(6.5, 3) #=> 122.522113490002
|
77
|
+
def cylinder_surface_area(radius, height)
|
78
|
+
return circumference(radius) * height
|
79
|
+
end
|
80
|
+
|
81
|
+
# Calculates the volume of a cylinder given radius and height.
|
82
|
+
# @param radius [Int, Float]
|
83
|
+
# radius >= 0; radius is in a unit of length
|
84
|
+
# @param height [Int, Float]
|
85
|
+
# height >= 0; height has the same units as radius
|
86
|
+
# @return [Float]
|
87
|
+
# return value >= 0; return value has the same units as radius
|
88
|
+
# @example
|
89
|
+
# cylinder_volume(6.5, 3) #=> 398.196868842506
|
90
|
+
def cylinder_volume(radius, height)
|
91
|
+
return circle_area(radius) * height
|
92
|
+
end
|
data/lib/joules/kinematics.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing kinematics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Kinematics module (kinematics.rb)
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# @param time [Int, Float]
|
15
15
|
# time > 0; time is in seconds
|
16
16
|
# @return [Float]
|
17
|
-
#
|
17
|
+
# return value >= 0; return value is in meters per second
|
18
18
|
# @example
|
19
19
|
# avg_speed(30, 2.4) #=> 12.5
|
20
20
|
def avg_speed(distance, time)
|
@@ -27,7 +27,7 @@ end
|
|
27
27
|
# @param time [Int, Float]
|
28
28
|
# time > 0; time is in seconds
|
29
29
|
# @return [Float]
|
30
|
-
#
|
30
|
+
# return value is in meters per second
|
31
31
|
# @example
|
32
32
|
# avg_velocity(180, 4.8) #=> 37.5
|
33
33
|
def avg_velocity(displacement, time)
|
@@ -42,7 +42,7 @@ end
|
|
42
42
|
# @param time [Int, Float]
|
43
43
|
# time > 0; time is in seconds
|
44
44
|
# @return [Float]
|
45
|
-
#
|
45
|
+
# return value is in meters per second squared
|
46
46
|
# @example
|
47
47
|
# acceleration(20, 35, 2.4) #=> 6.25
|
48
48
|
def acceleration(initial_velocity, final_velocity, time)
|
@@ -57,7 +57,7 @@ end
|
|
57
57
|
# @param time [Int, Float]
|
58
58
|
# time >= 0; time is in seconds
|
59
59
|
# @return [Float]
|
60
|
-
#
|
60
|
+
# return value is in meters per second
|
61
61
|
# @example
|
62
62
|
# final_velocity_v1(20, 6.25, 2.4) #=> 35.0
|
63
63
|
# @note There is one other method for calculating final velocity.
|
@@ -73,7 +73,7 @@ end
|
|
73
73
|
# @param displacement [Int, Float]
|
74
74
|
# displacement is in meters
|
75
75
|
# @return [Float]
|
76
|
-
#
|
76
|
+
# return value is in meters per second
|
77
77
|
# @example
|
78
78
|
# final_velocity_v2(20, 6.25, 66) #=> 35.0
|
79
79
|
# @note There is one other method for calculating final velocity.
|
@@ -89,7 +89,7 @@ end
|
|
89
89
|
# @param time [Int, Float]
|
90
90
|
# time >= 0; time is in seconds
|
91
91
|
# @return [Float]
|
92
|
-
#
|
92
|
+
# return value is in meters
|
93
93
|
# @example
|
94
94
|
# displacement_v1(20, 35, 2.4) #=> 66.0
|
95
95
|
# @note There are two other methods for calculating displacement.
|
@@ -105,7 +105,7 @@ end
|
|
105
105
|
# @param time [Int, Float]
|
106
106
|
# time >= 0; time is in seconds
|
107
107
|
# @return [Float]
|
108
|
-
#
|
108
|
+
# return value is in meters
|
109
109
|
# @example
|
110
110
|
# displacement_v2(20, 6.25, 2.4) #=> 66.0
|
111
111
|
# @note There are two other methods for calculating displacement.
|
@@ -121,7 +121,7 @@ end
|
|
121
121
|
# @param time [Int, Float]
|
122
122
|
# time >= 0; time is in seconds
|
123
123
|
# @return [Float]
|
124
|
-
#
|
124
|
+
# return value is in meters
|
125
125
|
# @example
|
126
126
|
# displacement_v3(35, 6.25, 2.4) #=> 66.0
|
127
127
|
# @note There are two other methods for calculating displacement.
|
data/lib/joules/mass_weight.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing mass and weight formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Mass and weight module (mass_weight.rb)
|
@@ -14,7 +14,7 @@ require_relative 'constants'
|
|
14
14
|
# @param mass [Int, Float]
|
15
15
|
# mass >= 0; mass is in kilograms
|
16
16
|
# @return [Float]
|
17
|
-
#
|
17
|
+
# return value >= 0; return value is in newtons
|
18
18
|
# @example
|
19
19
|
# weight(79.41) #=> 779.0121
|
20
20
|
def weight(mass)
|
@@ -25,7 +25,7 @@ end
|
|
25
25
|
# @param weight [Int, Float]
|
26
26
|
# weight >= 0; weight is in newtons
|
27
27
|
# @return [Float]
|
28
|
-
#
|
28
|
+
# return value >= 0; return value is in kilograms
|
29
29
|
# @example
|
30
30
|
# mass(779.0121) #=> 79.41
|
31
31
|
def mass(weight)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing momentum and impulse formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Momentum and impulse module (momentum_impulse.rb)
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# @param velocity [Int, Float]
|
15
15
|
# velocity is in meters per second
|
16
16
|
# @return [Float]
|
17
|
-
#
|
17
|
+
# return value is in newton seconds
|
18
18
|
# @example
|
19
19
|
# momentum(52, 4.7) #=> 244.4
|
20
20
|
def momentum(mass, velocity)
|
@@ -27,7 +27,7 @@ end
|
|
27
27
|
# @param time [Int, Float]
|
28
28
|
# time >= 0; time is in seconds
|
29
29
|
# @return [Float]
|
30
|
-
#
|
30
|
+
# return value is in newton seconds
|
31
31
|
# @example
|
32
32
|
# impulse_v1(30.8, 9.6) #=> 295.68
|
33
33
|
# @note There is one other method for calculating impulse.
|
@@ -43,7 +43,7 @@ end
|
|
43
43
|
# @param mass [Int, Float]
|
44
44
|
# mass >= 0; mass is in kilograms
|
45
45
|
# @return [Float]
|
46
|
-
#
|
46
|
+
# return value is in newton seconds
|
47
47
|
# @example
|
48
48
|
# impulse_v2(20, 35, 2.4) #=> 36.0
|
49
49
|
# @note There is one other method for calculating impulse.
|
data/lib/joules/pressure.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing pressure formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Pressure module (pressure.rb)
|
@@ -16,7 +16,7 @@ require_relative 'constants'
|
|
16
16
|
# @param area [Int, Float]
|
17
17
|
# area > 0; area is in meters cubed
|
18
18
|
# @return [Float]
|
19
|
-
#
|
19
|
+
# return value >= 0; return value is in pascals
|
20
20
|
# @example
|
21
21
|
# pressure(98, 0.04) #=> 2450.0
|
22
22
|
def pressure(force, area)
|
@@ -29,7 +29,7 @@ end
|
|
29
29
|
# @param height [Int, Float]
|
30
30
|
# height >= 0; height is in meters
|
31
31
|
# @return [Float]
|
32
|
-
#
|
32
|
+
# return value >= 0; return value is in pascals
|
33
33
|
# @example
|
34
34
|
# hydrostatic_pressure(1000, 5) #=> 49050.0
|
35
35
|
def hydrostatic_pressure(density, height)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing thermodynamics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Thermodynamics module (thermodynamics.rb)
|
@@ -16,10 +16,10 @@
|
|
16
16
|
# @param temperature_change [Int, Float]
|
17
17
|
# temperature_change is in celcius
|
18
18
|
# @return [Float]
|
19
|
-
#
|
19
|
+
# return value is in joules
|
20
20
|
# @example
|
21
21
|
# energy_v1(500, 2.46, 3.6) #=> 4428.0
|
22
|
-
# @note There
|
22
|
+
# @note There are two other methods for calculating energy.
|
23
23
|
def energy_v1(mass, specific_heat_capacity, temperature_change)
|
24
24
|
return mass * specific_heat_capacity * temperature_change.to_f
|
25
25
|
end
|
@@ -30,10 +30,10 @@ end
|
|
30
30
|
# @param specific_latent_heat [Int, Float]
|
31
31
|
# specific_latent_heat >= 0; specific_latent_heat is in joules per kilogram
|
32
32
|
# @return [Float]
|
33
|
-
#
|
33
|
+
# return value is in joules
|
34
34
|
# @example
|
35
35
|
# energy_v2(84.3, 72.1) #=> 6078.03
|
36
|
-
# @note There
|
36
|
+
# @note There are two other methods for calculating energy.
|
37
37
|
def energy_v2(mass, specific_latent_heat)
|
38
38
|
return mass * specific_latent_heat.to_f
|
39
39
|
end
|
data/lib/joules/waves.rb
CHANGED
@@ -3,18 +3,20 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing waves formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Waves module (waves.rb)
|
10
10
|
|
11
|
+
require_relative 'conversion'
|
12
|
+
|
11
13
|
# Calculates the wave speed given frequency and wavelength.
|
12
14
|
# @param frequency [Int, Float]
|
13
15
|
# frequency > 0; frequency is in hertz
|
14
16
|
# @param wavelength [Int, Float]
|
15
17
|
# wavelength >= 0; wavelength is in meters
|
16
18
|
# @return [Float]
|
17
|
-
#
|
19
|
+
# return value >= 0; return value is in meters per second
|
18
20
|
# @example
|
19
21
|
# wave_speed(3250, 0.1) #=> 325.0
|
20
22
|
def wave_speed(frequency, wavelength)
|
@@ -27,7 +29,7 @@ end
|
|
27
29
|
# @param frequency [Int, Float]
|
28
30
|
# frequency > 0; frequency is in hertz
|
29
31
|
# @return [Float]
|
30
|
-
#
|
32
|
+
# return value is in meters
|
31
33
|
# @example
|
32
34
|
# wavelength(325, 3250) #=> 0.1
|
33
35
|
def wavelength(wave_speed, frequency)
|
@@ -40,7 +42,7 @@ end
|
|
40
42
|
# @param wavelength [Int, Float]
|
41
43
|
# wavelength > 0; wavelength is in meters
|
42
44
|
# @return [Float]
|
43
|
-
#
|
45
|
+
# return value is in hertz
|
44
46
|
# @example
|
45
47
|
# frequency_v1(325, 0.1) #=> 3250.0
|
46
48
|
# @note There is one other method for calculating frequency.
|
@@ -52,7 +54,7 @@ end
|
|
52
54
|
# @param time_period [Int, Float]
|
53
55
|
# time_period > 0; time_period is in seconds
|
54
56
|
# @return [Float]
|
55
|
-
#
|
57
|
+
# return value > 0; return value is in hertz
|
56
58
|
# @example
|
57
59
|
# frequency_v2(12.5) #=> 0.08
|
58
60
|
# @note There is one other method for calculating frequency.
|
@@ -64,9 +66,34 @@ end
|
|
64
66
|
# @param frequency [Int, Float]
|
65
67
|
# frequency > 0; frequency is in hertz
|
66
68
|
# @return [Float]
|
67
|
-
#
|
69
|
+
# return value > 0; return value is in hertz
|
68
70
|
# @example
|
69
71
|
# time_period(0.08) #=> 12.5
|
70
72
|
def time_period(frequency)
|
71
73
|
return 1.0 / frequency
|
72
74
|
end
|
75
|
+
|
76
|
+
# Calculates the refractive index of a substance given angle of incidence and angle of refraction.
|
77
|
+
# @param angle_of_incidence [Int, Float]
|
78
|
+
# angle_of_incidence is in degrees
|
79
|
+
# @param angle_of_refraction [Int, Float]
|
80
|
+
# angle_of_refraction is in degrees
|
81
|
+
# @return [Float]
|
82
|
+
# @example
|
83
|
+
# refractive_index_v1(50, 35) #=> 1.3355577296591308
|
84
|
+
# @note There is one other method for calculating refractive index.
|
85
|
+
def refractive_index_v1(angle_of_incidence, angle_of_refraction)
|
86
|
+
return Math.sin(to_radians(angle_of_incidence)) /
|
87
|
+
Math.sin(to_radians(angle_of_refraction))
|
88
|
+
end
|
89
|
+
|
90
|
+
# Calculates the refractive index of a substance given critical angle.
|
91
|
+
# @param critical_angle [Int, Float]
|
92
|
+
# critical_angle != 0; critical_angle is in degrees
|
93
|
+
# @return [Float]
|
94
|
+
# @example
|
95
|
+
# refractive_index_v2(48.7535) #=> 1.3299993207924483
|
96
|
+
# @note There is one other method for calculating refractive index.
|
97
|
+
def refractive_index_v2(critical_angle)
|
98
|
+
return 1.0 / Math.sin(to_radians(critical_angle))
|
99
|
+
end
|
data/lib/joules.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing Physics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.2.0 25/05/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Joules module (joules.rb)
|
@@ -18,3 +18,6 @@ require 'joules/energy_work_power'
|
|
18
18
|
require 'joules/pressure'
|
19
19
|
require 'joules/thermodynamics'
|
20
20
|
require 'joules/waves'
|
21
|
+
require 'joules/electricity'
|
22
|
+
require 'joules/geometry'
|
23
|
+
require 'joules/conversion'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: joules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elisha Lai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " Joules is a library (gem) for providing simple Physics formulas\n
|
14
14
|
\ in kinematics, forces, waves, electricity, and so much more. A\n selection
|
@@ -20,9 +20,12 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- lib/joules.rb
|
22
22
|
- lib/joules/constants.rb
|
23
|
+
- lib/joules/conversion.rb
|
23
24
|
- lib/joules/density.rb
|
25
|
+
- lib/joules/electricity.rb
|
24
26
|
- lib/joules/energy_work_power.rb
|
25
27
|
- lib/joules/forces.rb
|
28
|
+
- lib/joules/geometry.rb
|
26
29
|
- lib/joules/kinematics.rb
|
27
30
|
- lib/joules/mass_weight.rb
|
28
31
|
- lib/joules/momentum_impulse.rb
|