joules 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/joules.rb +2 -1
- data/lib/joules/circular_motion.rb +160 -0
- data/lib/joules/constants.rb +1 -1
- data/lib/joules/conversion.rb +1 -1
- data/lib/joules/density.rb +1 -1
- data/lib/joules/electric_fields.rb +1 -1
- data/lib/joules/electricity.rb +1 -1
- data/lib/joules/energy_work_power.rb +8 -6
- data/lib/joules/forces.rb +19 -4
- data/lib/joules/geometry.rb +1 -1
- data/lib/joules/gravitational_fields.rb +1 -1
- data/lib/joules/kinematics.rb +1 -1
- data/lib/joules/magnetic_fields.rb +4 -4
- data/lib/joules/mass_weight.rb +1 -1
- data/lib/joules/momentum_impulse.rb +1 -1
- data/lib/joules/pressure.rb +1 -1
- data/lib/joules/quantum.rb +1 -1
- data/lib/joules/stress_strain.rb +1 -1
- data/lib/joules/thermodynamics.rb +1 -1
- data/lib/joules/waves.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98b2e0c6df0fd3755eb58eaad979471c569ac1a6
|
4
|
+
data.tar.gz: 275a48df9e2c4dff48105fbecfa35edb20b4c442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37eb1b3cdd2c77fde36b2a2873cad5386885a2d2e5adb9410a943e784078a7e7def52dde7f661c132ff0059d67aacb03ee12b638d361666a38e17eb04f390f74
|
7
|
+
data.tar.gz: 6ab629ad3ea3ab4b4f87a520c2a524176dc6a37b8ff908e062572c53f3226961031ad9001ac3f1305d47e4d2d3d21ddd50e90de26c486c01df4ad53f08ba940a
|
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.
|
18
|
+
gem install joules-0.4.0.gem
|
19
19
|
```
|
20
20
|
|
21
21
|
### Library Import
|
@@ -64,8 +64,10 @@ This would return 23.4.
|
|
64
64
|
* Added Physics formulas in gravitational fields and electric fields
|
65
65
|
|
66
66
|
#### Version 0.3.2
|
67
|
-
* Added Physics formulas in magnetic fields
|
68
|
-
|
67
|
+
* Added Physics formulas in magnetic fields, stress, and strain
|
68
|
+
|
69
|
+
#### Version 0.4.0
|
70
|
+
* Added Physics formulas in circular motion
|
69
71
|
|
70
72
|
### Contribution
|
71
73
|
Please feel free to submit any ideas, questions, or problems by reporting an issue.
|
data/lib/joules.rb
CHANGED
@@ -3,13 +3,14 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing Physics formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Joules module (joules.rb)
|
10
10
|
|
11
11
|
require 'joules/constants'
|
12
12
|
require 'joules/kinematics'
|
13
|
+
require 'joules/circular_motion'
|
13
14
|
require 'joules/mass_weight'
|
14
15
|
require 'joules/density'
|
15
16
|
require 'joules/forces'
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#==============================================================================
|
2
|
+
# Joules
|
3
|
+
#
|
4
|
+
# @description: Module for providing circular motion formulas
|
5
|
+
# @author: Elisha Lai
|
6
|
+
# @version: 0.4.0 06/06/2015
|
7
|
+
#==============================================================================
|
8
|
+
|
9
|
+
# Circular motion module (circular_motion.rb)
|
10
|
+
|
11
|
+
module Joules
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Calculates the angular velocity given linear velocity and radius.
|
15
|
+
# @param linear_velocity [Int, Float]
|
16
|
+
# linear_velocity is in metres per second
|
17
|
+
# @param radius [Int, Float]
|
18
|
+
# radius > 0; radius is in metres
|
19
|
+
# @return [Float]
|
20
|
+
# return value is in radians per second
|
21
|
+
# @raise [ZeroDivisionError] if radius = 0
|
22
|
+
# @example
|
23
|
+
# Joules.angular_velocity_v1(9, 3) #=> 3.0
|
24
|
+
# @note There is one other method for calculating angular velocity.
|
25
|
+
def angular_velocity_v1(linear_velocity, radius)
|
26
|
+
if radius.zero?
|
27
|
+
raise ZeroDivisionError.new('divided by 0')
|
28
|
+
else
|
29
|
+
return linear_velocity / radius.to_f
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Calculates the angular velocity given frequency of rotation.
|
34
|
+
# @param frequency_of_rotation [Int, Float]
|
35
|
+
# frequency_of_rotation >= 0; frequency_of_rotation is in hertz
|
36
|
+
# @return [Float]
|
37
|
+
# return value >= 0; return value is in radians per second
|
38
|
+
# @example
|
39
|
+
# Joules.angular_velocity_v2(1.5) #=> 9.42477796076938
|
40
|
+
# @note There is one other method for calculating angular velocity.
|
41
|
+
def angular_velocity_v2(frequency_of_rotation)
|
42
|
+
return 2 * Math::PI * frequency_of_rotation
|
43
|
+
end
|
44
|
+
|
45
|
+
# Calculates the angular acceleration given initial angular velocity, final angular velocity, and time.
|
46
|
+
# @param initial_angular_velocity [Int, Float]
|
47
|
+
# initial_angular_velocity is in radians per second
|
48
|
+
# @param final_angular_velocity [Int, Float]
|
49
|
+
# final_angular_velocity is in radians per second
|
50
|
+
# @param time [Int, Float]
|
51
|
+
# time > 0; time is in seconds
|
52
|
+
# @return [Float]
|
53
|
+
# return value is in radians per second squared
|
54
|
+
# @raise [ZeroDivisionError] if time = 0
|
55
|
+
# @example
|
56
|
+
# Joules.angular_acceleration(20, 35, 2.4) #=> 6.25
|
57
|
+
def angular_acceleration(initial_angular_velocity, final_angular_velocity, time)
|
58
|
+
if time.zero?
|
59
|
+
raise ZeroDivisionError.new('divided by 0')
|
60
|
+
else
|
61
|
+
return (final_angular_velocity - initial_angular_velocity) / time.to_f
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Calculates the centripetal acceleration given linear velocity and radius.
|
66
|
+
# @param linear_velocity [Int, Float]
|
67
|
+
# linear_velocity is in metres per second
|
68
|
+
# @param radius [Int, Float]
|
69
|
+
# radius > 0; radius is in metres
|
70
|
+
# @return [Float]
|
71
|
+
# return value >= 0; return value is in metres per second squared
|
72
|
+
# @raise [ZeroDivisionError] if radius = 0
|
73
|
+
# @example
|
74
|
+
# Joules.centripetal_acceleration_v1(9, 3) #=> 27.0
|
75
|
+
# @note There is one other method for calculating centripetal acceleration.
|
76
|
+
def centripetal_acceleration_v1(linear_velocity, radius)
|
77
|
+
if radius.zero?
|
78
|
+
raise ZeroDivisionError.new('divided by 0')
|
79
|
+
else
|
80
|
+
return (linear_velocity ** 2.0) / radius
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Calculates the centripetal acceleration given angular velocity and radius.
|
85
|
+
# @param angular_velocity [Int, Float]
|
86
|
+
# angular_velocity is in radians per second
|
87
|
+
# @param radius [Int, Float]
|
88
|
+
# radius >= 0; radius is in metres
|
89
|
+
# @return [Float]
|
90
|
+
# return value >= 0; return value is in metres per second squared
|
91
|
+
# @example
|
92
|
+
# Joules.centripetal_acceleration_v2(3, 3) #=> 27.0
|
93
|
+
# @note There is one other method for calculating centripetal acceleration.
|
94
|
+
def centripetal_acceleration_v2(angular_velocity, radius)
|
95
|
+
return (angular_velocity ** 2.0) * radius
|
96
|
+
end
|
97
|
+
|
98
|
+
# Calculates the centripetal force given mass, linear velocity, and radius.
|
99
|
+
# @param mass [Int, Float]
|
100
|
+
# mass >= 0; mass is in kilograms
|
101
|
+
# @param linear_velocity [Int, Float]
|
102
|
+
# linear_velocity is in metres per second
|
103
|
+
# @param radius [Int, Float]
|
104
|
+
# radius >= 0; radius is in metres
|
105
|
+
# @return [Float]
|
106
|
+
# return value >= 0; return value is in newtons
|
107
|
+
# @example
|
108
|
+
# Joules.centripetal_force_v1(2000, 5.56, 2.1) #=> 29441.523809523802
|
109
|
+
# @note There is one other method for calculating centripetal force.
|
110
|
+
def centripetal_force_v1(mass, linear_velocity, radius)
|
111
|
+
if radius.zero?
|
112
|
+
raise ZeroDivisionError.new('divided by 0')
|
113
|
+
else
|
114
|
+
return (mass * (linear_velocity ** 2.0)) / radius
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Calculates the centripetal force given mass, angular velocity, and radius.
|
119
|
+
# @param mass [Int, Float]
|
120
|
+
# mass >= 0; mass is in kilograms
|
121
|
+
# @param angular_velocity [Int, Float]
|
122
|
+
# angular_velocity is in radians per second
|
123
|
+
# @param radius [Int, Float]
|
124
|
+
# radius >= 0; radius is in metres
|
125
|
+
# @return [Float]
|
126
|
+
# return value >= 0; return value is in newtons
|
127
|
+
# @example
|
128
|
+
# Joules.centripetal_force_v2(53.5, 3, 3) #=> 1444.5
|
129
|
+
# @note There is one other method for calculating centripetal force.
|
130
|
+
def centripetal_force_v2(mass, angular_velocity, radius)
|
131
|
+
return mass * (angular_velocity ** 2.0) * radius
|
132
|
+
end
|
133
|
+
|
134
|
+
# Calculates the angular momentum given moment of inertia and angular velocity.
|
135
|
+
# @param moment_of_inertia [Int, Float]
|
136
|
+
# moment_of_inertia is in kilogram metres squared
|
137
|
+
# @param angular_velocity [Int, Float]
|
138
|
+
# angular_velocity is in radians per second
|
139
|
+
# @return [Float]
|
140
|
+
# return value is in kilogram metres squared per second
|
141
|
+
# @example
|
142
|
+
# Joules.angular_momentum(2, 2.5) #=> 5.0
|
143
|
+
def angular_momentum(moment_of_inertia, angular_velocity)
|
144
|
+
return moment_of_inertia * angular_velocity.to_f
|
145
|
+
end
|
146
|
+
|
147
|
+
# Calculates the angular kinetic energy given moment of inertia and angular velocity.
|
148
|
+
# @param moment_of_inertia [Int, Float]
|
149
|
+
# moment_of_inertia is in kilogram metres squared
|
150
|
+
# @param angular_velocity [Int, Float]
|
151
|
+
# angular_velocity is in radians per second
|
152
|
+
# @return [Float]
|
153
|
+
# return value is in joules
|
154
|
+
# @example
|
155
|
+
# Joules.angular_kinetic_energy(5, 2.3) #=> 13.224999999999998
|
156
|
+
def angular_kinetic_energy(moment_of_inertia, angular_velocity)
|
157
|
+
return 0.5 * moment_of_inertia * (angular_velocity ** 2)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
data/lib/joules/constants.rb
CHANGED
data/lib/joules/conversion.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing conversion formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Conversion module (conversion.rb)
|
data/lib/joules/density.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing electric fields formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Electric fields module (electric_fields.rb)
|
data/lib/joules/electricity.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing electricity formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Electricity module (electricity.rb)
|
@@ -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.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Energy, work, and power module (energy_work_power.rb)
|
@@ -51,7 +51,7 @@ module Joules
|
|
51
51
|
return 0.5 * mass * (velocity ** 2)
|
52
52
|
end
|
53
53
|
|
54
|
-
# Calculates the work done given force and
|
54
|
+
# Calculates the work done given force, displacement, and angle.
|
55
55
|
# @param force [Int, Float]
|
56
56
|
# force is in newtons
|
57
57
|
# @param displacement [Int, Float]
|
@@ -63,7 +63,7 @@ module Joules
|
|
63
63
|
# @example
|
64
64
|
# Joules.work_done(40, 2.34) #=> 93.6
|
65
65
|
def work_done(force, displacement, angle = 0)
|
66
|
-
return force * displacement
|
66
|
+
return force * displacement * Math.cos(to_radians(angle))
|
67
67
|
end
|
68
68
|
|
69
69
|
# Calculates the power given work done and time.
|
@@ -85,18 +85,20 @@ module Joules
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
# Calculates the power given force and
|
88
|
+
# Calculates the power given force, velocity, and angle.
|
89
89
|
# @param force [Int, Float]
|
90
90
|
# force is in newtons
|
91
91
|
# @param velocity [Int, Float]
|
92
92
|
# velocity is in meters per second
|
93
|
+
# @param angle [Int, Float]
|
94
|
+
# angle is in degrees
|
93
95
|
# @return [Float]
|
94
96
|
# return value is in watts
|
95
97
|
# @example
|
96
98
|
# Joules.power_v2(42, 2.3) #=> 96.6
|
97
99
|
# @note There are four other methods for calculating power.
|
98
|
-
def power_v2(force, velocity)
|
99
|
-
return force * velocity.
|
100
|
+
def power_v2(force, velocity, angle = 0)
|
101
|
+
return force * velocity * Math.cos(to_radians(angle))
|
100
102
|
end
|
101
103
|
|
102
104
|
# Calculates the energy efficiency given useful energy output and energy 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.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Forces module (forces.rb)
|
@@ -62,17 +62,32 @@ module Joules
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
# Calculates the
|
65
|
+
# Calculates the maximum friction force given coefficient of friction and normal force.
|
66
|
+
# @param coefficient_of_friction [Int, Float]
|
67
|
+
# coefficient_of_friction >= 0
|
68
|
+
# @param normal_force [Int, Force]
|
69
|
+
# normal_force is in newtons
|
70
|
+
# @return [Float]
|
71
|
+
# return value is in newtons
|
72
|
+
# @example
|
73
|
+
# Joules.maximum_friction_force(0.4, 29.43) #=> 11.772
|
74
|
+
def maximum_friction_force(coefficient_of_friction, normal_force)
|
75
|
+
return coefficient_of_friction * normal_force.to_f
|
76
|
+
end
|
77
|
+
|
78
|
+
# Calculates the moment given force, distance, and angle.
|
66
79
|
# @param force [Int, Float]
|
67
80
|
# force is in newtons
|
68
81
|
# @param distance [Int, Float]
|
69
82
|
# distance >= 0; distance is in metres
|
83
|
+
# @param angle [Int, Float]
|
84
|
+
# angle is in degrees
|
70
85
|
# @return [Float]
|
71
86
|
# return value is in newton metres
|
72
87
|
# @example
|
73
88
|
# Joules.moment(23, 4.5) #=> 103.5
|
74
|
-
def moment(force, distance)
|
75
|
-
return force * distance.
|
89
|
+
def moment(force, distance, angle = 90)
|
90
|
+
return force * distance * Math.sin(to_radians(angle))
|
76
91
|
end
|
77
92
|
|
78
93
|
end
|
data/lib/joules/geometry.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing gravitational fields formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Gravitational fields module (gravitational_fields.rb)
|
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.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Kinematics module (kinematics.rb)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing magnetic fields formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Magnetic fields module (magnetic_fields.rb)
|
@@ -11,7 +11,7 @@
|
|
11
11
|
module Joules
|
12
12
|
module_function
|
13
13
|
|
14
|
-
# Calculates the magnetic force on a current given flux density, current,
|
14
|
+
# Calculates the magnetic force on a current given flux density, current, conductor length, and angle.
|
15
15
|
# @param flux_density [Int, Float]
|
16
16
|
# flux_density is in teslas
|
17
17
|
# @param current [Int, Float]
|
@@ -29,7 +29,7 @@ module Joules
|
|
29
29
|
return flux_density * current * conductor_length * Math.sin(to_radians(angle))
|
30
30
|
end
|
31
31
|
|
32
|
-
# Calculates the magnetic force on a moving charge given flux density, charge, and
|
32
|
+
# Calculates the magnetic force on a moving charge given flux density, charge, velocity, and angle.
|
33
33
|
# @param flux_density [Int, Float]
|
34
34
|
# flux_density is in teslas
|
35
35
|
# @param charge [Int, Float]
|
@@ -47,7 +47,7 @@ module Joules
|
|
47
47
|
return flux_density * charge * velocity * Math.sin(to_radians(angle))
|
48
48
|
end
|
49
49
|
|
50
|
-
# Calculates the magnetic flux given flux density and
|
50
|
+
# Calculates the magnetic flux given flux density, area, and angle.
|
51
51
|
# @param flux_density [Int, Float]
|
52
52
|
# flux_density is in teslas
|
53
53
|
# @param area [Int, Float]
|
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.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Mass and weight module (mass_weight.rb)
|
@@ -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.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Momentum and impulse module (momentum_impulse.rb)
|
data/lib/joules/pressure.rb
CHANGED
data/lib/joules/quantum.rb
CHANGED
data/lib/joules/stress_strain.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# @description: Module for providing stress and strain formulas
|
5
5
|
# @author: Elisha Lai
|
6
|
-
# @version: 0.
|
6
|
+
# @version: 0.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Stress and strain module (stress_strain.rb)
|
@@ -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.4.0 06/06/2015
|
7
7
|
#==============================================================================
|
8
8
|
|
9
9
|
# Thermodynamics module (thermodynamics.rb)
|
data/lib/joules/waves.rb
CHANGED
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.4.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-06-
|
11
|
+
date: 2015-06-06 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
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- LICENSE.md
|
22
22
|
- README.md
|
23
23
|
- lib/joules.rb
|
24
|
+
- lib/joules/circular_motion.rb
|
24
25
|
- lib/joules/constants.rb
|
25
26
|
- lib/joules/conversion.rb
|
26
27
|
- lib/joules/density.rb
|