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
@@ -3,115 +3,118 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing energy, work, and power formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Energy, work, and power module (energy_work_power.rb)
|
10
10
|
|
11
|
-
|
11
|
+
module Joules
|
12
|
+
module_function
|
12
13
|
|
13
|
-
# Calculates the gravitational potential energy given mass and height.
|
14
|
-
# @param mass [Int, Float]
|
15
|
-
# mass >= 0; mass is in kilograms
|
16
|
-
# @param height [Int, Float]
|
17
|
-
# height >= 0; height is in meters
|
18
|
-
# @return [Float]
|
19
|
-
# return value >= 0; return value is in joules
|
20
|
-
# @example
|
21
|
-
# gravitational_potential_energy(0.5, 6) #=> 29.43
|
22
|
-
def gravitational_potential_energy(mass, height)
|
23
|
-
|
24
|
-
end
|
14
|
+
# Calculates the gravitational potential energy given mass and height.
|
15
|
+
# @param mass [Int, Float]
|
16
|
+
# mass >= 0; mass is in kilograms
|
17
|
+
# @param height [Int, Float]
|
18
|
+
# height >= 0; height is in meters
|
19
|
+
# @return [Float]
|
20
|
+
# return value >= 0; return value is in joules
|
21
|
+
# @example
|
22
|
+
# Joules.gravitational_potential_energy(0.5, 6) #=> 29.43
|
23
|
+
def gravitational_potential_energy(mass, height)
|
24
|
+
return mass * FREE_FALL_ACCELERATION * height
|
25
|
+
end
|
25
26
|
|
26
|
-
# Calculates the elastic potential energy given spring constant and extension.
|
27
|
-
# @param spring_constant [Int, Float]
|
28
|
-
# spring_constant >= 0; spring_constant is in newtons per meter
|
29
|
-
# @param extension [Int, Float]
|
30
|
-
# extension >= 0; extension is in meters
|
31
|
-
# @return [Float]
|
32
|
-
# return value >= 0; return value is in joules
|
33
|
-
# @example
|
34
|
-
# elastic_potential_energy(81.75, 2.4) #=> 235.44
|
35
|
-
def elastic_potential_energy(spring_constant, extension)
|
36
|
-
|
37
|
-
end
|
27
|
+
# Calculates the elastic potential energy given spring constant and extension.
|
28
|
+
# @param spring_constant [Int, Float]
|
29
|
+
# spring_constant >= 0; spring_constant is in newtons per meter
|
30
|
+
# @param extension [Int, Float]
|
31
|
+
# extension >= 0; extension is in meters
|
32
|
+
# @return [Float]
|
33
|
+
# return value >= 0; return value is in joules
|
34
|
+
# @example
|
35
|
+
# Joules.elastic_potential_energy(81.75, 2.4) #=> 235.44
|
36
|
+
def elastic_potential_energy(spring_constant, extension)
|
37
|
+
return 0.5 * spring_constant * (extension ** 2)
|
38
|
+
end
|
38
39
|
|
39
|
-
# Calculates the kinetic energy given mass and velocity.
|
40
|
-
# @param mass [Int, Float]
|
41
|
-
# mass >= 0; mass is in kilograms
|
42
|
-
# @param velocity [Int, Float]
|
43
|
-
# velocity is in meters per second
|
44
|
-
# @return [Float]
|
45
|
-
# return value >= 0; return value is in joules
|
46
|
-
# @example
|
47
|
-
# kinetic_energy(500, 22) #=> 121000.0
|
48
|
-
def kinetic_energy(mass, velocity)
|
49
|
-
|
50
|
-
end
|
40
|
+
# Calculates the kinetic energy given mass and velocity.
|
41
|
+
# @param mass [Int, Float]
|
42
|
+
# mass >= 0; mass is in kilograms
|
43
|
+
# @param velocity [Int, Float]
|
44
|
+
# velocity is in meters per second
|
45
|
+
# @return [Float]
|
46
|
+
# return value >= 0; return value is in joules
|
47
|
+
# @example
|
48
|
+
# Joules.kinetic_energy(500, 22) #=> 121000.0
|
49
|
+
def kinetic_energy(mass, velocity)
|
50
|
+
return 0.5 * mass * (velocity ** 2)
|
51
|
+
end
|
51
52
|
|
52
|
-
# Calculates the work done given force and displacement.
|
53
|
-
# @param force [Int, Float]
|
54
|
-
# force is in newtons
|
55
|
-
# @param displacement [Int, Float]
|
56
|
-
# displacement is in meters
|
57
|
-
# @return [Float]
|
58
|
-
# return value is in joules
|
59
|
-
# @example
|
60
|
-
# work_done(40, 2.34) #=> 93.6
|
61
|
-
def work_done(force, displacement)
|
62
|
-
|
63
|
-
end
|
53
|
+
# Calculates the work done given force and displacement.
|
54
|
+
# @param force [Int, Float]
|
55
|
+
# force is in newtons
|
56
|
+
# @param displacement [Int, Float]
|
57
|
+
# displacement is in meters
|
58
|
+
# @return [Float]
|
59
|
+
# return value is in joules
|
60
|
+
# @example
|
61
|
+
# Joules.work_done(40, 2.34) #=> 93.6
|
62
|
+
def work_done(force, displacement)
|
63
|
+
return force * displacement.to_f
|
64
|
+
end
|
64
65
|
|
65
|
-
# Calculates the power given work done and time.
|
66
|
-
# @param work_done [Int, Float]
|
67
|
-
# work_done is in joules
|
68
|
-
# @param time [Int, Float]
|
69
|
-
# time > 0; time is in seconds
|
70
|
-
# @return [Float]
|
71
|
-
# return value is in watts
|
72
|
-
# @example
|
73
|
-
# power_v1(28, 7) #=> 4.0
|
74
|
-
# @note There are four other methods for calculating power.
|
75
|
-
def power_v1(work_done, time)
|
76
|
-
|
77
|
-
end
|
66
|
+
# Calculates the power given work done and time.
|
67
|
+
# @param work_done [Int, Float]
|
68
|
+
# work_done is in joules
|
69
|
+
# @param time [Int, Float]
|
70
|
+
# time > 0; time is in seconds
|
71
|
+
# @return [Float]
|
72
|
+
# return value is in watts
|
73
|
+
# @example
|
74
|
+
# Joules.power_v1(28, 7) #=> 4.0
|
75
|
+
# @note There are four other methods for calculating power.
|
76
|
+
def power_v1(work_done, time)
|
77
|
+
return work_done / time.to_f
|
78
|
+
end
|
78
79
|
|
79
|
-
# Calculates the power given force and velocity.
|
80
|
-
# @param force [Int, Float]
|
81
|
-
# force is in newtons
|
82
|
-
# @param velocity [Int, Float]
|
83
|
-
# velocity is in meters per second
|
84
|
-
# @return [Float]
|
85
|
-
# return value is in watts
|
86
|
-
# @example
|
87
|
-
# power_v2(42, 2.3) #=> 96.6
|
88
|
-
# @note There are four other methods for calculating power.
|
89
|
-
def power_v2(force, velocity)
|
90
|
-
|
91
|
-
end
|
80
|
+
# Calculates the power given force and velocity.
|
81
|
+
# @param force [Int, Float]
|
82
|
+
# force is in newtons
|
83
|
+
# @param velocity [Int, Float]
|
84
|
+
# velocity is in meters per second
|
85
|
+
# @return [Float]
|
86
|
+
# return value is in watts
|
87
|
+
# @example
|
88
|
+
# Joules.power_v2(42, 2.3) #=> 96.6
|
89
|
+
# @note There are four other methods for calculating power.
|
90
|
+
def power_v2(force, velocity)
|
91
|
+
return force * velocity.to_f
|
92
|
+
end
|
92
93
|
|
93
|
-
# Calculates the energy efficiency given useful energy output and energy input.
|
94
|
-
# @param useful_energy_output [Int, Float]
|
95
|
-
# 0 <= useful_energy_output <= energy_input; useful_energy_output is in joules
|
96
|
-
# @param energy_input [Int, Float]
|
97
|
-
# energy_input > 0; energy_input is in joules
|
98
|
-
# @return [Float]
|
99
|
-
# return value >= 0
|
100
|
-
# @example
|
101
|
-
# energy_efficiency(16, 20) #=> 80.0
|
102
|
-
def energy_efficiency(useful_energy_output, energy_input)
|
103
|
-
|
104
|
-
end
|
94
|
+
# Calculates the energy efficiency given useful energy output and energy input.
|
95
|
+
# @param useful_energy_output [Int, Float]
|
96
|
+
# 0 <= useful_energy_output <= energy_input; useful_energy_output is in joules
|
97
|
+
# @param energy_input [Int, Float]
|
98
|
+
# energy_input > 0; energy_input is in joules
|
99
|
+
# @return [Float]
|
100
|
+
# return value >= 0
|
101
|
+
# @example
|
102
|
+
# Joules.energy_efficiency(16, 20) #=> 80.0
|
103
|
+
def energy_efficiency(useful_energy_output, energy_input)
|
104
|
+
return (useful_energy_output / energy_input.to_f) * 100
|
105
|
+
end
|
106
|
+
|
107
|
+
# Calculates the power efficiency given useful power output and power input.
|
108
|
+
# @param useful_power_output [Int, Float]
|
109
|
+
# 0 <= useful_power_output <= power_input; useful_power_output is in watts
|
110
|
+
# @param power_input [Int, Float]
|
111
|
+
# power_input > 0; power_input is in watts
|
112
|
+
# @return [Float]
|
113
|
+
# return value >= 0
|
114
|
+
# @example
|
115
|
+
# Joules.power_efficiency(26, 40) #=> 65.0
|
116
|
+
def power_efficiency(useful_power_output, power_input)
|
117
|
+
return (useful_power_output / power_input.to_f) * 100
|
118
|
+
end
|
105
119
|
|
106
|
-
# Calculates the power efficiency given useful power output and power input.
|
107
|
-
# @param useful_power_output [Int, Float]
|
108
|
-
# 0 <= useful_power_output <= power_input; useful_power_output is in watts
|
109
|
-
# @param power_input [Int, Float]
|
110
|
-
# power_input > 0; power_input is in watts
|
111
|
-
# @return [Float]
|
112
|
-
# return value >= 0
|
113
|
-
# @example
|
114
|
-
# power_efficiency(26, 40) #=> 65.0
|
115
|
-
def power_efficiency(useful_power_output, power_input)
|
116
|
-
return (useful_power_output / power_input.to_f) * 100
|
117
120
|
end
|
data/lib/joules/forces.rb
CHANGED
@@ -3,66 +3,71 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing forces formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Forces module (forces.rb)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
# mass >= 0; mass is in kilograms
|
14
|
-
# @param acceleration [Int, Float]
|
15
|
-
# acceleration is in meters per second squared
|
16
|
-
# @return [Float]
|
17
|
-
# return value is in newtons
|
18
|
-
# @example
|
19
|
-
# force_v1(120, 2.67) #=> 320.4
|
20
|
-
# @note There are two other methods for calculating force.
|
21
|
-
def force_v1(mass, acceleration)
|
22
|
-
return mass * acceleration.to_f
|
23
|
-
end
|
11
|
+
module Joules
|
12
|
+
module_function
|
24
13
|
|
25
|
-
# Calculates the force given
|
26
|
-
# @param
|
27
|
-
#
|
28
|
-
# @param
|
29
|
-
#
|
30
|
-
# @return [Float]
|
31
|
-
# return value
|
32
|
-
# @example
|
33
|
-
#
|
34
|
-
# @note There are two other methods for calculating force.
|
35
|
-
def
|
36
|
-
|
37
|
-
end
|
14
|
+
# Calculates the force given mass and acceleration.
|
15
|
+
# @param mass [Int, Float]
|
16
|
+
# mass >= 0; mass is in kilograms
|
17
|
+
# @param acceleration [Int, Float]
|
18
|
+
# acceleration is in meters per second squared
|
19
|
+
# @return [Float]
|
20
|
+
# return value is in newtons
|
21
|
+
# @example
|
22
|
+
# Joules.force_v1(120, 2.67) #=> 320.4
|
23
|
+
# @note There are two other methods for calculating force.
|
24
|
+
def force_v1(mass, acceleration)
|
25
|
+
return mass * acceleration.to_f
|
26
|
+
end
|
38
27
|
|
39
|
-
# Calculates the force given
|
40
|
-
# @param
|
41
|
-
#
|
42
|
-
# @param
|
43
|
-
#
|
44
|
-
# @
|
45
|
-
#
|
46
|
-
# @
|
47
|
-
#
|
48
|
-
# @
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
28
|
+
# Calculates the force given spring constant and extension.
|
29
|
+
# @param spring_constant [Int, Float]
|
30
|
+
# spring_constant >= 0; spring_constant is in newtons per meter
|
31
|
+
# @param extension [Int, Float]
|
32
|
+
# extension >= 0; extension is in meters
|
33
|
+
# @return [Float]
|
34
|
+
# return value >= 0; return value is in newtons
|
35
|
+
# @example
|
36
|
+
# Joules.force_v2(81.75, 2.4) #=> 196.2
|
37
|
+
# @note There are two other methods for calculating force.
|
38
|
+
def force_v2(spring_constant, extension)
|
39
|
+
return spring_constant * extension.to_f
|
40
|
+
end
|
41
|
+
|
42
|
+
# Calculates the force given initial velocity, final velocity, mass, and time.
|
43
|
+
# @param initial_velocity [Int, Float]
|
44
|
+
# initial_velocity is in meters per second
|
45
|
+
# @param final_velocity [Int, Float]
|
46
|
+
# final_velocity is in meters per second
|
47
|
+
# @param mass [Int, Float]
|
48
|
+
# mass >= 0; mass is in kilograms
|
49
|
+
# @param time [Int, Float]
|
50
|
+
# time > 0; time is in seconds
|
51
|
+
# @return [Float]
|
52
|
+
# return value is in newtons
|
53
|
+
# @example
|
54
|
+
# Joules.force_v3(20, 35, 50, 2.4) #=> 312.5
|
55
|
+
# @note There are two other methods for calculating force.
|
56
|
+
def force_v3(initial_velocity, final_velocity, mass, time)
|
57
|
+
return ((final_velocity - initial_velocity) * mass) / time.to_f
|
58
|
+
end
|
59
|
+
|
60
|
+
# Calculates the moment given force and distance.
|
61
|
+
# @param force [Int, Float]
|
62
|
+
# force is in newtons
|
63
|
+
# @param distance [Int, Float]
|
64
|
+
# distance >= 0; distance is in meters
|
65
|
+
# @return [Float]
|
66
|
+
# return value is in newton metres
|
67
|
+
# @example
|
68
|
+
# Joules.moment(23, 4.5) #=> 103.5
|
69
|
+
def moment(force, distance)
|
70
|
+
return force * distance.to_f
|
71
|
+
end
|
56
72
|
|
57
|
-
# Calculates the moment given force and distance.
|
58
|
-
# @param force [Int, Float]
|
59
|
-
# force is in newtons
|
60
|
-
# @param distance [Int, Float]
|
61
|
-
# distance >= 0; distance is in meters
|
62
|
-
# @return [Float]
|
63
|
-
# return value is in newton metres
|
64
|
-
# @example
|
65
|
-
# moment(23, 4.5) #=> 103.5
|
66
|
-
def moment(force, distance)
|
67
|
-
return force * distance.to_f
|
68
73
|
end
|
data/lib/joules/geometry.rb
CHANGED
@@ -3,129 +3,134 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing geometry formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.3.
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Geometry module (geometry.rb)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
# length >= 0; length is in a unit of length
|
14
|
-
# @param width [Int, Float]
|
15
|
-
# width >= 0; width has the same units as length
|
16
|
-
# @return [Float]
|
17
|
-
# return value >= 0; return value has the same units as length
|
18
|
-
# @example
|
19
|
-
# rectangle_area(2, 3.4) #=> 6.8
|
20
|
-
def rectangle_area(length, width)
|
21
|
-
return length * width.to_f
|
22
|
-
end
|
11
|
+
module Joules
|
12
|
+
module_function
|
23
13
|
|
24
|
-
# Calculates the
|
25
|
-
# @param
|
26
|
-
#
|
27
|
-
# @param
|
28
|
-
#
|
29
|
-
# @return [Float]
|
30
|
-
# return value >= 0; return value has the same units as
|
31
|
-
# @example
|
32
|
-
#
|
33
|
-
def
|
34
|
-
|
35
|
-
end
|
14
|
+
# Calculates the area of a rectangle given length and width.
|
15
|
+
# @param length [Int, Float]
|
16
|
+
# length >= 0; length is in a unit of length
|
17
|
+
# @param width [Int, Float]
|
18
|
+
# width >= 0; width has the same units as length
|
19
|
+
# @return [Float]
|
20
|
+
# return value >= 0; return value has the same units as length
|
21
|
+
# @example
|
22
|
+
# Joules.rectangle_area(2, 3.4) #=> 6.8
|
23
|
+
def rectangle_area(length, width)
|
24
|
+
return length * width.to_f
|
25
|
+
end
|
36
26
|
|
37
|
-
# Calculates the
|
38
|
-
# @param radius [Int, Float]
|
39
|
-
# radius >= 0; radius is in a unit of length
|
40
|
-
# @
|
41
|
-
#
|
42
|
-
# @
|
43
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
27
|
+
# Calculates the arc length of a circle given radius and central angle.
|
28
|
+
# @param radius [Int, Float]
|
29
|
+
# radius >= 0; radius is in a unit of length
|
30
|
+
# @param central_angle [Int, Float]
|
31
|
+
# central_angle >= 0; central_angle is in radians
|
32
|
+
# @return [Float]
|
33
|
+
# return value >= 0; return value has the same units as radius
|
34
|
+
# @example
|
35
|
+
# Joules.arc_length(12, (Math::PI/4)) #=> 9.42477796076938
|
36
|
+
def arc_length(radius, central_angle)
|
37
|
+
return radius * central_angle.to_f
|
38
|
+
end
|
47
39
|
|
48
|
-
# Calculates the
|
49
|
-
# @param radius [Int, Float]
|
50
|
-
# radius >= 0; radius is in a unit of length
|
51
|
-
# @return [Float]
|
52
|
-
# return value >= 0; return value has the same units as radius
|
53
|
-
# @example
|
54
|
-
#
|
55
|
-
def
|
56
|
-
|
57
|
-
end
|
40
|
+
# Calculates the circumference of a circle given radius.
|
41
|
+
# @param radius [Int, Float]
|
42
|
+
# radius >= 0; radius is in a unit of length
|
43
|
+
# @return [Float]
|
44
|
+
# return value >= 0; return value has the same units as radius
|
45
|
+
# @example
|
46
|
+
# Joules.circumference(12) #=> 75.398223686155
|
47
|
+
def circumference(radius)
|
48
|
+
return 2 * Math::PI * radius
|
49
|
+
end
|
58
50
|
|
59
|
-
# Calculates the
|
60
|
-
# @param radius [Int, Float]
|
61
|
-
# radius >= 0; radius is in a unit of length
|
62
|
-
# @return [Float]
|
63
|
-
# return value >= 0; return value has the same units as radius
|
64
|
-
# @example
|
65
|
-
#
|
66
|
-
def
|
67
|
-
|
68
|
-
end
|
51
|
+
# Calculates the area of a circle given radius.
|
52
|
+
# @param radius [Int, Float]
|
53
|
+
# radius >= 0; radius is in a unit of length
|
54
|
+
# @return [Float]
|
55
|
+
# return value >= 0; return value has the same units as radius
|
56
|
+
# @example
|
57
|
+
# Joules.circle_area(12) #=> 452.38934211693
|
58
|
+
def circle_area(radius)
|
59
|
+
return Math::PI * (radius ** 2)
|
60
|
+
end
|
69
61
|
|
70
|
-
# Calculates the
|
71
|
-
# @param radius [Int, Float]
|
72
|
-
# radius >= 0; radius is in a unit of length
|
73
|
-
# @return [Float]
|
74
|
-
# return value >= 0; return value has the same units as radius
|
75
|
-
# @example
|
76
|
-
#
|
77
|
-
def
|
78
|
-
|
79
|
-
end
|
62
|
+
# Calculates the surface area of a sphere given radius.
|
63
|
+
# @param radius [Int, Float]
|
64
|
+
# radius >= 0; radius is in a unit of length
|
65
|
+
# @return [Float]
|
66
|
+
# return value >= 0; return value has the same units as radius
|
67
|
+
# @example
|
68
|
+
# Joules.sphere_surface_area(12) #=> 1809.5573684677208
|
69
|
+
def sphere_surface_area(radius)
|
70
|
+
return 4 * circle_area(radius)
|
71
|
+
end
|
80
72
|
|
81
|
-
# Calculates the
|
82
|
-
# @param radius [Int, Float]
|
83
|
-
# radius >= 0; radius is in a unit of length
|
84
|
-
# @
|
85
|
-
#
|
86
|
-
# @
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
return circle_area(radius) + (Math::PI * radius * slant_height)
|
92
|
-
end
|
73
|
+
# Calculates the volume of a sphere given radius.
|
74
|
+
# @param radius [Int, Float]
|
75
|
+
# radius >= 0; radius is in a unit of length
|
76
|
+
# @return [Float]
|
77
|
+
# return value >= 0; return value has the same units as radius
|
78
|
+
# @example
|
79
|
+
# Joules.sphere_volume(12) #=> 7238.229473870883
|
80
|
+
def sphere_volume(radius)
|
81
|
+
return (4 * circle_area(radius) * radius) / 3
|
82
|
+
end
|
93
83
|
|
94
|
-
# Calculates the
|
95
|
-
# @param radius [Int, Float]
|
96
|
-
# radius >= 0; radius is in a unit of length
|
97
|
-
# @param
|
98
|
-
#
|
99
|
-
# @return [Float]
|
100
|
-
# return value >= 0; return value has the same units as radius
|
101
|
-
# @example
|
102
|
-
#
|
103
|
-
def
|
104
|
-
|
105
|
-
end
|
84
|
+
# Calculates the surface area of a cone given radius and slant height.
|
85
|
+
# @param radius [Int, Float]
|
86
|
+
# radius >= 0; radius is in a unit of length
|
87
|
+
# @param slant_height [Int, Float]
|
88
|
+
# slant_height >= 0; slant_height has the same units as radius
|
89
|
+
# @return [Float]
|
90
|
+
# return value >= 0; return value has the same units as radius
|
91
|
+
# @example
|
92
|
+
# Joules.cone_surface_area(3, 5.83) #=> 83.22078939359362
|
93
|
+
def cone_surface_area(radius, slant_height)
|
94
|
+
return circle_area(radius) + (Math::PI * radius * slant_height)
|
95
|
+
end
|
106
96
|
|
107
|
-
#
|
108
|
-
# @param radius [Int, Float]
|
109
|
-
# radius >= 0; radius is in a unit of length
|
110
|
-
# @param height [Int, Float]
|
111
|
-
# height >= 0; height has the same units as radius
|
112
|
-
# @return [Float]
|
113
|
-
# return value >= 0; return value has the same units as radius
|
114
|
-
# @example
|
115
|
-
#
|
116
|
-
def
|
117
|
-
|
118
|
-
end
|
97
|
+
# Calculates the volume of a cone given radius and height.
|
98
|
+
# @param radius [Int, Float]
|
99
|
+
# radius >= 0; radius is in a unit of length
|
100
|
+
# @param height [Int, Float]
|
101
|
+
# height >= 0; height has the same units as radius
|
102
|
+
# @return [Float]
|
103
|
+
# return value >= 0; return value has the same units as radius
|
104
|
+
# @example
|
105
|
+
# Joules.cone_volume(6.5, 3) #=> 132.73228961416876
|
106
|
+
def cone_volume(radius, height)
|
107
|
+
return (circle_area(radius) * height) / 3
|
108
|
+
end
|
109
|
+
|
110
|
+
# Calulates the surface area of a cylinder given radius and height.
|
111
|
+
# @param radius [Int, Float]
|
112
|
+
# radius >= 0; radius is in a unit of length
|
113
|
+
# @param height [Int, Float]
|
114
|
+
# height >= 0; height has the same units as radius
|
115
|
+
# @return [Float]
|
116
|
+
# return value >= 0; return value has the same units as radius
|
117
|
+
# @example
|
118
|
+
# Joules.cylinder_surface_area(6.5, 3) #=> 122.522113490002
|
119
|
+
def cylinder_surface_area(radius, height)
|
120
|
+
return circumference(radius) * height
|
121
|
+
end
|
122
|
+
|
123
|
+
# Calculates the volume of a cylinder given radius and height.
|
124
|
+
# @param radius [Int, Float]
|
125
|
+
# radius >= 0; radius is in a unit of length
|
126
|
+
# @param height [Int, Float]
|
127
|
+
# height >= 0; height has the same units as radius
|
128
|
+
# @return [Float]
|
129
|
+
# return value >= 0; return value has the same units as radius
|
130
|
+
# @example
|
131
|
+
# Joules.cylinder_volume(6.5, 3) #=> 398.196868842506
|
132
|
+
def cylinder_volume(radius, height)
|
133
|
+
return circle_area(radius) * height
|
134
|
+
end
|
119
135
|
|
120
|
-
# Calculates the volume of a cylinder given radius and height.
|
121
|
-
# @param radius [Int, Float]
|
122
|
-
# radius >= 0; radius is in a unit of length
|
123
|
-
# @param height [Int, Float]
|
124
|
-
# height >= 0; height has the same units as radius
|
125
|
-
# @return [Float]
|
126
|
-
# return value >= 0; return value has the same units as radius
|
127
|
-
# @example
|
128
|
-
# cylinder_volume(6.5, 3) #=> 398.196868842506
|
129
|
-
def cylinder_volume(radius, height)
|
130
|
-
return circle_area(radius) * height
|
131
136
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing gravitational fields formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.3.1 01/06/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Gravitational fields module (gravitational_fields.rb)
|
10
|
+
|
11
|
+
module Joules
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Calculates the gravitational force given object mass 1, object mass 2, and distance between the centres of the two objects.
|
15
|
+
# @param object_mass1 [Int, Float]
|
16
|
+
# object_mass1 >= 0; object_mass1 is in kilograms
|
17
|
+
# @param object_mass2 [Int, Float]
|
18
|
+
# object_mass2 >= 0; object_mass2 is in kilograms
|
19
|
+
# @param distance [Int, Float]
|
20
|
+
# distance > 0; distance is in meters
|
21
|
+
# @return [Float]
|
22
|
+
# return value >= 0; return value is in newtons
|
23
|
+
# @example
|
24
|
+
# Joules.gravitational_force(2e30, 1.9e27, 7.8e11) #=> 4.166009204470743e+23
|
25
|
+
def gravitational_force(object_mass1, object_mass2, distance)
|
26
|
+
return (GRAVITATIONAL_CONSTANT * object_mass1 * object_mass2) /
|
27
|
+
(distance ** 2)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Calculates the gravitational field strength given force and mass.
|
31
|
+
# @param force [Int, Float]
|
32
|
+
# force is in newtons
|
33
|
+
# @param mass [Int, Float]
|
34
|
+
# mass > 0; mass is in kilograms
|
35
|
+
# @return [Float]
|
36
|
+
# return value is in meters per second squared
|
37
|
+
# @example
|
38
|
+
# Joules.gravitational_field_strength_v1(20, 0.5) #=> 40.0
|
39
|
+
# @note There is one other method for calculating gravitational field strength.
|
40
|
+
def gravitational_field_strength_v1(force, mass)
|
41
|
+
return force / mass.to_f
|
42
|
+
end
|
43
|
+
|
44
|
+
# Calculates the gravitational field strength given mass and distance.
|
45
|
+
# @param mass [Int, Float]
|
46
|
+
# mass >= 0; mass is in kilograms
|
47
|
+
# @param distance [Int, Float]
|
48
|
+
# distance > 0; distance is in meters
|
49
|
+
# @return [Float]
|
50
|
+
# return value >= 0; return value is in meters per second squared
|
51
|
+
# @example
|
52
|
+
# Joules.gravitational_field_strength_v2(34.7, 9.3) #=> 2.6760203491733148e-11
|
53
|
+
# @note There is one other method for calculating gravitational field strength.
|
54
|
+
def gravitational_field_strength_v2(mass, distance)
|
55
|
+
return (GRAVITATIONAL_CONSTANT * mass) / (distance ** 2)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Calculates the gravitational potential given mass and distance.
|
59
|
+
# @param mass [Int, Float]
|
60
|
+
# mass >= 0; mass is in kilograms
|
61
|
+
# @param distance [Int, Float]
|
62
|
+
# distance > 0; distance is in meters
|
63
|
+
# @return [Float]
|
64
|
+
# return value <= 0; return value is in joules per kilogram
|
65
|
+
# @example
|
66
|
+
# Joules.gravitational_potential(6e24, 6.4e6) #=> -62531250.0
|
67
|
+
def gravitational_potential(mass, distance)
|
68
|
+
return (-GRAVITATIONAL_CONSTANT * mass) / distance
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|