Module: Joules
- Defined in:
- lib/joules/waves.rb,
lib/joules/forces.rb,
lib/joules/density.rb,
lib/joules/quantum.rb,
lib/joules/geometry.rb,
lib/joules/pressure.rb,
lib/joules/constants.rb,
lib/joules/conversion.rb,
lib/joules/kinematics.rb,
lib/joules/electricity.rb,
lib/joules/mass_weight.rb,
lib/joules/oscillations.rb,
lib/joules/stress_strain.rb,
lib/joules/thermodynamics.rb,
lib/joules/circular_motion.rb,
lib/joules/electric_fields.rb,
lib/joules/magnetic_fields.rb,
lib/joules/momentum_impulse.rb,
lib/joules/energy_work_power.rb,
lib/joules/gravitational_fields.rb
Overview
Gravitational fields module (gravitational_fields.rb)
Constant Summary collapse
- SPEED_OF_LIGHT =
Note:
This quantity is in metres per second.
Speed of light in free space.
3.00e8
- FREE_SPACE_PERMEABILITY =
Note:
This quantity is in henries per metre.
Permeability of free space.
(4 * Math::PI * 1e-7)
- FREE_SPACE_PERMITTIVITY =
Note:
This quantity is in farads per metre.
Permittivity of free space.
8.85e-12
- ELEMENTARY_CHARGE =
Note:
This quantity is in coulombs.
Elementary charge.
1.6e-19
- PLANCK_CONSTANT =
Note:
This quantity is in joule seconds.
Planck constant.
6.63e-34
- UNIFIED_ATOMIC_MASS_UNIT =
Note:
This quantiy is in kilograms.
Unified atomic mass unit.
1.66e-27
- ELECTRON_MASS =
Note:
This quantity is in kilograms.
Rest mass of electron.
9.11e-31
- PROTON_MASS =
Note:
This quantity is in kilograms.
Rest mass of proton.
1.67e-27
- NEUTRON_MASS =
Note:
This quantity is in kilograms.
Rest mass of neutron.
1.67e-27
- MOLAR_GAS_CONSTANT =
Note:
This quantity is in joules per kelvin mole.
Molar gas constant.
8.31
- AVOGADRO_CONSTANT =
Note:
This quantity is in per mole.
Avogadro constant.
6.02e23
- BOLTZMANN_CONSTANT =
Note:
This quantity is in joules per kelvin.
Boltzmann constant.
1.38e-23
- STEFAN_CONSTANT =
Note:
This quantity is in watts per metre squared kelvin to the fourth power.
Stefan constant.
5.67e-8
- WIEN_CONSTANT =
Note:
This quantity is in metre kelvins.
Wien constant.
2.9e-3
- GRAVITATIONAL_CONSTANT =
Note:
This quantity is in newton metres squared per kilogram squared.
Gravitational constant.
6.67e-11
- FREE_FALL_ACCELERATION =
Note:
This quantity is in metres per second squared.
Acceleration of free fall.
9.81
Waves Methods collapse
-
.focal_length(object_distance, image_distance) ⇒ Float
Calculates the focal length of a lens given object distance and image distance.
-
.frequency_v1(wave_speed, wavelength) ⇒ Float
Calculates the frequency given wave speed and wavelength.
-
.frequency_v2(time_period) ⇒ Float
Calculates the frequency given time period.
-
.magnification(image_height, object_height) ⇒ Float
Calculates the magnification given image height and object height.
-
.power_of_lens(focal_length) ⇒ Float
Calculates the power of a lens given focal length.
-
.refractive_index_v1(angle_of_incidence, angle_of_refraction) ⇒ Float
Calculates the refractive index of a substance given angle of incidence and angle of refraction.
-
.refractive_index_v2(critical_angle) ⇒ Float
Calculates the refractive index of a substance given critical angle.
-
.time_period_v1(frequency) ⇒ Float
Calculates the time period given frequency.
-
.wave_speed(frequency, wavelength) ⇒ Float
Calculates the wave speed given frequency and wavelength.
-
.wavelength(wave_speed, frequency) ⇒ Float
Calculates the wavelength given wave speed and frequency.
Forces Methods collapse
-
.buoyant_force(density, volume_of_liquid_displaced) ⇒ Float
Calculates the buoyant force given density and volume of liquid displaced.
-
.force_v1(mass, acceleration) ⇒ Float
Calculates the force given mass and acceleration.
-
.force_v2(spring_constant, extension) ⇒ Float
Calculates the force given spring constant and extension.
-
.force_v3(initial_velocity, final_velocity, mass, time) ⇒ Float
Calculates the force given initial velocity, final velocity, mass, and time.
-
.maximum_friction_force(coefficient_of_friction, normal_force) ⇒ Float
Calculates the maximum friction force given coefficient of friction and normal force.
-
.moment(force, distance, angle = 90) ⇒ Float
Calculates the moment given force, distance, and angle.
Density Methods collapse
-
.density(mass, volume) ⇒ Float
Calculates the density given mass and volume.
Quantum Methods collapse
-
.decay_constant(half_life) ⇒ Float
Calculates the decay constant of a decaying quantity given half-life.
-
.energy_v4(mass) ⇒ Float
Calculates the energy given mass.
-
.half_life(decay_constant) ⇒ Float
Calculates the half-life of a decaying quantity given decay constant.
-
.photon_energy(frequency) ⇒ Float
Calculates the photon energy given frequency.
Arc Length Method collapse
-
.arc_length(radius, central_angle) ⇒ Float
Calculates the arc length of a circle given radius and central angle.
Circumference Method collapse
-
.circumference(radius) ⇒ Float
Calculates the circumference of a circle given radius.
Area Methods collapse
-
.circle_area(radius) ⇒ Float
Calculates the area of a circle given radius.
-
.rectangle_area(length, width) ⇒ Float
Calculates the area of a rectangle given length and width.
-
.trapezium_area(top_base, bottom_base, height) ⇒ Float
Calculates the area of a trapezium given top base, bottom base, and height.
-
.triangle_area(base, height) ⇒ Float
Calculates the area of a triangle given base and height.
Volume Methods collapse
-
.cone_volume(radius, height) ⇒ Float
Calculates the volume of a cone given radius and height.
-
.cylinder_volume(radius, height) ⇒ Float
Calculates the volume of a cylinder given radius and height.
-
.sphere_volume(radius) ⇒ Float
Calculates the volume of a sphere given radius.
Surface Area Methods collapse
-
.cone_surface_area(radius, slant_height) ⇒ Float
Calculates the surface area of a cone given radius and slant height.
-
.cylinder_surface_area(radius, height) ⇒ Float
Calulates the surface area of a cylinder given radius and height.
-
.sphere_surface_area(radius) ⇒ Float
Calculates the surface area of a sphere given radius.
Pressure Methods collapse
-
.hydrostatic_pressure(density, height) ⇒ Float
Calculates the hydrostatic pressure given density and height.
-
.pressure(force, area) ⇒ Float
Calculates the pressure given force and area.
Angle Conversion Methods collapse
-
.to_degrees(angle) ⇒ Float
Calculates the equivalent angle in degrees given radians.
-
.to_radians(angle) ⇒ Float
Calculates the equivalent angle in radians given degrees.
Temperature Conversion Methods collapse
-
.to_celcius(temperature) ⇒ Float
Calculates the equivalent temperature in celcius given kelvins.
-
.to_kelvins(temperature) ⇒ Float
Calculates the equivalent temperature in kelvins given celcius.
Velocity Conversion Methods collapse
-
.to_kilometres_per_hour(velocity) ⇒ Float
Calculates the equivalent velocity in kilometres per hour given metres per second.
-
.to_metres_per_second(velocity) ⇒ Float
Calculates the equivalent velocity in metres per second given kilometres per hour.
Kinematics Methods collapse
-
.acceleration(initial_velocity, final_velocity, time) ⇒ Float
Calculates the acceleration given initial velocity, final velocity, and time.
-
.avg_speed(distance, time) ⇒ Float
Calculates the average speed given distance and time.
-
.avg_velocity(displacement, time) ⇒ Float
Calculates the average velocity given displacement and time.
-
.displacement_v1(initial_velocity, final_velocity, time) ⇒ Float
Calculates the displacement given initial velocity, final velocity, and time.
-
.displacement_v2(initial_velocity, acceleration, time) ⇒ Float
Calculates the displacement given initial velocity, acceleration, and time.
-
.displacement_v3(final_velocity, acceleration, time) ⇒ Float
Calculates the displacement given final velocity, acceleration, and time.
-
.final_velocity_v1(initial_velocity, acceleration, time) ⇒ Float
Calculates the final velocity given initial velocity, acceleration, and time.
-
.final_velocity_v2(initial_velocity, acceleration, displacement) ⇒ Float
Calculates the final velocity given initial velocity, acceleration, and displacement.
Electricity Methods collapse
-
.capacitance(charge, voltage) ⇒ Float
Calculates the total capacitance given charge and voltage.
-
.capacitance_in_parallel(capacitances) ⇒ Float
Calculates the total capacitance of capacitors in parallel.
-
.capacitance_in_series(capacitances) ⇒ Float
Calculates the total capacitance of capacitors in series.
-
.capacitor_potential_energy_v1(charge, voltage) ⇒ Float
Calculates the capacitor potential energy given charge and voltage.
-
.capacitor_potential_energy_v2(capacitance, voltage) ⇒ Float
Calculates the capacitor potential energy given capacitance and voltage.
-
.capacitor_potential_energy_v3(charge, capacitance) ⇒ Float
Calculates the capacitor potential energy given charge and capacitance.
-
.current_v1(charge, time) ⇒ Float
Calculates the current given charge and time.
-
.current_v2(cross_sectional_area, charge_density, drift_velocity, charge) ⇒ Float
Calculates the current given cross sectional area, charge density, drift velocity, and charge.
-
.energy_v3(voltage, current, time) ⇒ Float
Calculates the energy given voltage, current, and time.
-
.power_v3(voltage, current) ⇒ Float
Calculates the power given voltage and current.
-
.power_v4(current, resistance) ⇒ Float
Calculates the power given current and resistance.
-
.power_v5(voltage, resistance) ⇒ Float
Calculates the power given voltage and resistance.
-
.resistance_in_parallel(resistances) ⇒ Float
Calculates the total resistance of resistors in parallel.
-
.resistance_in_series(resistances) ⇒ Float
Calculates the total resistance of resistors in series.
-
.resistance_v1(voltage, current) ⇒ Float
Calculates the resistance given voltage and current.
-
.resistance_v2(resistivity, wire_length, cross_sectional_area) ⇒ Float
Calculates the resistance given resistivity, wire length, and cross sectional area.
-
.voltage_v1(energy, charge) ⇒ Float
Calculates the voltage given energy and charge.
-
.voltage_v2(current, resistance) ⇒ Float
Calculates the voltage given current and resistance.
Mass and Weight Methods collapse
-
.mass(weight) ⇒ Float
Calculates the mass given weight.
-
.weight(mass) ⇒ Float
Calculates the weight given mass.
Oscillations Methods collapse
-
.max_particle_acceleration(angular_velocity, amplitude) ⇒ Float
Calculates the maximum acceleration of a particle in oscillation given angular velocity and amplitude.
-
.max_particle_speed(angular_velocity, amplitude) ⇒ Float
Calculates the maximum speed of a particle in oscillation given angular velocity and amplitude.
-
.particle_acceleration(angular_velocity, particle_displacement) ⇒ Float
Calculates the acceleration of a particle in oscillation given angular velocity and particle displacement.
-
.particle_displacement(amplitude, angular_velocity, time) ⇒ Float
Calculates the displacement of a particle in oscillation given amplitude, angular velocity, and time.
-
.particle_velocity(angular_velocity, amplitude, particle_displacement, return_sign = nil) ⇒ Float+
Calculates the velocity of a particle in oscillation given angular velocity, amplitude, and particle displacement.
-
.time_period_v2(mass, spring_constant) ⇒ Float
Calculates the time period of a mass-spring system given mass and spring constant.
-
.time_period_v3(pendulum_length) ⇒ Float
Calculates the time period of a simple pendulum given pendulum length.
Stress and Strain Methods collapse
-
.tensile_strain(extension, length) ⇒ Float
Calculates the tensile strain given extension and length.
-
.tensile_stress(force, area) ⇒ Float
Calculates the tensile stress given force and area.
-
.young_modulus(tensile_stress, tensile_strain) ⇒ Float
Calculates the Young modulus given tensile stress and tensile strain.
Thermodynamics Methods collapse
-
.energy_v1(mass, specific_heat_capacity, temperature_change) ⇒ Float
Calculates the energy given mass, specific heat capacity, and temperature change.
-
.energy_v2(mass, specific_latent_heat) ⇒ Float
Calculates the energy given mass and specific latent heat.
Circular Motion Methods collapse
-
.angular_acceleration(initial_angular_velocity, final_angular_velocity, time) ⇒ Float
Calculates the angular acceleration given initial angular velocity, final angular velocity, and time.
-
.angular_kinetic_energy(moment_of_inertia, angular_velocity) ⇒ Float
Calculates the angular kinetic energy given moment of inertia and angular velocity.
-
.angular_momentum(moment_of_inertia, angular_velocity) ⇒ Float
Calculates the angular momentum given moment of inertia and angular velocity.
-
.angular_velocity_v1(linear_velocity, radius) ⇒ Float
Calculates the angular velocity given linear velocity and radius.
-
.angular_velocity_v2(frequency_of_rotation) ⇒ Float
Calculates the angular velocity given frequency of rotation.
-
.centripetal_acceleration_v1(linear_velocity, radius) ⇒ Float
Calculates the centripetal acceleration given linear velocity and radius.
-
.centripetal_acceleration_v2(angular_velocity, radius) ⇒ Float
Calculates the centripetal acceleration given angular velocity and radius.
-
.centripetal_force_v1(mass, linear_velocity, radius) ⇒ Float
Calculates the centripetal force given mass, linear velocity, and radius.
-
.centripetal_force_v2(mass, angular_velocity, radius) ⇒ Float
Calculates the centripetal force given mass, angular velocity, and radius.
Electric Fields Methods collapse
-
.electric_field_strength_v1(voltage, distance) ⇒ Float
Calculates the electric field strength given voltage and distance between two plates.
-
.electric_field_strength_v2(force, charge) ⇒ Float
Calculates the electric field strength for an uniform field given force and charge.
-
.electric_field_strength_v3(charge, distance) ⇒ Float
Calculates the electric field strength for a radial field given charge and distance.
-
.electric_potential(charge, distance) ⇒ Float
Calculates the electric potential given charge and distance.
-
.kinetic_energy_v2(voltage, charge) ⇒ Float
Calculates the kinetic energy of an electron given voltage.
Magnetic Fields Methods collapse
-
.magnetic_flux(flux_density, area, angle = 0) ⇒ Float
Calculates the magnetic flux given flux density, area, and angle.
-
.magnetic_flux_linkage(magnetic_flux, number_of_coils) ⇒ Float
Calculates the magnetic flux linkage given magnetic flux and number of coils in the wire.
-
.magnetic_force_v1(flux_density, current, conductor_length, angle = 90) ⇒ Float
Calculates the magnetic force on a current given flux density, current, conductor length, and angle.
-
.magnetic_force_v2(flux_density, charge, velocity, angle = 90) ⇒ Float
Calculates the magnetic force on a moving charge given flux density, charge, velocity, and angle.
Momentum and Impulse Methods collapse
-
.impulse_v1(force, time) ⇒ Float
Calculates the impulse given force and time.
-
.impulse_v2(initial_velocity, final_velocity, mass) ⇒ Float
Calculates the impulse given initial velocity, final velocity, and mass.
-
.momentum(mass, velocity) ⇒ Float
Calculates the momentum given mass and velocity.
Energy, Work, and Power Methods collapse
-
.elastic_potential_energy(spring_constant, extension) ⇒ Float
Calculates the elastic potential energy given spring constant and extension.
-
.energy_efficiency(useful_energy_output, energy_input) ⇒ Float
Calculates the energy efficiency given useful energy output and energy input.
-
.gravitational_potential_energy(mass, height) ⇒ Float
Calculates the gravitational potential energy given mass and height.
-
.kinetic_energy_v1(mass, velocity) ⇒ Float
Calculates the kinetic energy given mass and velocity.
-
.power_efficiency(useful_power_output, power_input) ⇒ Float
Calculates the power efficiency given useful power output and power input.
-
.power_v1(work_done, time) ⇒ Float
Calculates the power given work done and time.
-
.power_v2(force, velocity, angle = 0) ⇒ Float
Calculates the power given force, velocity, and angle.
-
.work_done(force, displacement, angle = 0) ⇒ Float
Calculates the work done given force, displacement, and angle.
Gravitational Fields Methods collapse
-
.gravitational_field_strength_v1(force, mass) ⇒ Float
Calculates the gravitational field strength given force and mass.
-
.gravitational_field_strength_v2(mass, distance) ⇒ Float
Calculates the gravitational field strength given mass and distance.
-
.gravitational_force(object_mass1, object_mass2, distance) ⇒ Float
Calculates the gravitational force given object mass 1, object mass 2, and distance between the centres of the two objects.
-
.gravitational_potential(mass, distance) ⇒ Float
Calculates the gravitational potential given mass and distance.
Class Method Details
.acceleration(initial_velocity, final_velocity, time) ⇒ Float
Calculates the acceleration given initial velocity, final velocity, and time.
64 65 66 67 68 69 70 |
# File 'lib/joules/kinematics.rb', line 64 def acceleration(initial_velocity, final_velocity, time) if time.zero? raise ZeroDivisionError.new('divided by 0') else return (final_velocity - initial_velocity) / time.to_f end end |
.angular_acceleration(initial_angular_velocity, final_angular_velocity, time) ⇒ Float
Calculates the angular acceleration given initial angular velocity, final angular velocity, and time.
59 60 61 62 63 64 65 |
# File 'lib/joules/circular_motion.rb', line 59 def angular_acceleration(initial_angular_velocity, final_angular_velocity, time) if time.zero? raise ZeroDivisionError.new('divided by 0') else return (final_angular_velocity - initial_angular_velocity) / time.to_f end end |
.angular_kinetic_energy(moment_of_inertia, angular_velocity) ⇒ Float
Calculates the angular kinetic energy given moment of inertia and angular velocity.
158 159 160 |
# File 'lib/joules/circular_motion.rb', line 158 def angular_kinetic_energy(moment_of_inertia, angular_velocity) return 0.5 * moment_of_inertia * (angular_velocity ** 2) end |
.angular_momentum(moment_of_inertia, angular_velocity) ⇒ Float
Calculates the angular momentum given moment of inertia and angular velocity.
145 146 147 |
# File 'lib/joules/circular_motion.rb', line 145 def angular_momentum(moment_of_inertia, angular_velocity) return moment_of_inertia * angular_velocity.to_f end |
.angular_velocity_v1(linear_velocity, radius) ⇒ Float
There is one other method for calculating angular velocity.
Calculates the angular velocity given linear velocity and radius.
27 28 29 30 31 32 33 |
# File 'lib/joules/circular_motion.rb', line 27 def angular_velocity_v1(linear_velocity, radius) if radius.zero? raise ZeroDivisionError.new('divided by 0') else return linear_velocity / radius.to_f end end |
.angular_velocity_v2(frequency_of_rotation) ⇒ Float
There is one other method for calculating angular velocity.
Calculates the angular velocity given frequency of rotation.
43 44 45 |
# File 'lib/joules/circular_motion.rb', line 43 def angular_velocity_v2(frequency_of_rotation) return 2 * Math::PI * frequency_of_rotation end |
.arc_length(radius, central_angle) ⇒ Float
Calculates the arc length of a circle given radius and central angle.
25 26 27 |
# File 'lib/joules/geometry.rb', line 25 def arc_length(radius, central_angle) return radius * central_angle.to_f end |
.avg_speed(distance, time) ⇒ Float
Calculates the average speed given distance and time.
26 27 28 29 30 31 32 |
# File 'lib/joules/kinematics.rb', line 26 def avg_speed(distance, time) if time.zero? raise ZeroDivisionError.new('divided by 0') else return distance / time.to_f end end |
.avg_velocity(displacement, time) ⇒ Float
Calculates the average velocity given displacement and time.
44 45 46 47 48 49 50 |
# File 'lib/joules/kinematics.rb', line 44 def avg_velocity(displacement, time) if time.zero? raise ZeroDivisionError.new('divided by 0') else return displacement / time.to_f end end |
.buoyant_force(density, volume_of_liquid_displaced) ⇒ Float
Calculates the buoyant force given density and volume of liquid displaced.
89 90 91 |
# File 'lib/joules/forces.rb', line 89 def buoyant_force(density, volume_of_liquid_displaced) return density * FREE_FALL_ACCELERATION * volume_of_liquid_displaced end |
.capacitance(charge, voltage) ⇒ Float
Calculates the total capacitance given charge and voltage.
137 138 139 140 141 142 143 |
# File 'lib/joules/electricity.rb', line 137 def capacitance(charge, voltage) if voltage.zero? raise ZeroDivisionError.new('divided by 0') else return charge / voltage.to_f end end |
.capacitance_in_parallel(capacitances) ⇒ Float
Calculates the total capacitance of capacitors in parallel.
218 219 220 221 222 223 224 |
# File 'lib/joules/electricity.rb', line 218 def capacitance_in_parallel(capacitances) total_capacitance = 0 capacitances.each do |capacitance| total_capacitance += capacitance end return total_capacitance.to_f end |
.capacitance_in_series(capacitances) ⇒ Float
Calculates the total capacitance of capacitors in series.
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/joules/electricity.rb', line 199 def capacitance_in_series(capacitances) total_capacitance = 0 if capacitances.empty? return total_capacitance.to_f else capacitances.each do |capacitance| total_capacitance += (1.0 / capacitance) end return 1 / total_capacitance end end |
.capacitor_potential_energy_v1(charge, voltage) ⇒ Float
There are two other methods for calculating capacitor potential energy.
Calculates the capacitor potential energy given charge and voltage.
155 156 157 |
# File 'lib/joules/electricity.rb', line 155 def capacitor_potential_energy_v1(charge, voltage) return 0.5 * charge * voltage end |
.capacitor_potential_energy_v2(capacitance, voltage) ⇒ Float
There are two other methods for calculating capacitor potential energy.
Calculates the capacitor potential energy given capacitance and voltage.
169 170 171 |
# File 'lib/joules/electricity.rb', line 169 def capacitor_potential_energy_v2(capacitance, voltage) return 0.5 * capacitance * (voltage ** 2) end |
.capacitor_potential_energy_v3(charge, capacitance) ⇒ Float
There are two other methods for calculating capacitor potential energy.
Calculates the capacitor potential energy given charge and capacitance.
184 185 186 187 188 189 190 |
# File 'lib/joules/electricity.rb', line 184 def capacitor_potential_energy_v3(charge, capacitance) if capacitance.zero? raise ZeroDivisionError.new('divided by 0') else return (0.5 * (charge ** 2)) / capacitance end end |
.centripetal_acceleration_v1(linear_velocity, radius) ⇒ Float
There is one other method for calculating centripetal acceleration.
Calculates the centripetal acceleration given linear velocity and radius.
78 79 80 81 82 83 84 |
# File 'lib/joules/circular_motion.rb', line 78 def centripetal_acceleration_v1(linear_velocity, radius) if radius.zero? raise ZeroDivisionError.new('divided by 0') else return (linear_velocity ** 2.0) / radius end end |
.centripetal_acceleration_v2(angular_velocity, radius) ⇒ Float
There is one other method for calculating centripetal acceleration.
Calculates the centripetal acceleration given angular velocity and radius.
96 97 98 |
# File 'lib/joules/circular_motion.rb', line 96 def centripetal_acceleration_v2(angular_velocity, radius) return (angular_velocity ** 2.0) * radius end |
.centripetal_force_v1(mass, linear_velocity, radius) ⇒ Float
There is one other method for calculating centripetal force.
Calculates the centripetal force given mass, linear velocity, and radius.
112 113 114 115 116 117 118 |
# File 'lib/joules/circular_motion.rb', line 112 def centripetal_force_v1(mass, linear_velocity, radius) if radius.zero? raise ZeroDivisionError.new('divided by 0') else return (mass * (linear_velocity ** 2.0)) / radius end end |
.centripetal_force_v2(mass, angular_velocity, radius) ⇒ Float
There is one other method for calculating centripetal force.
Calculates the centripetal force given mass, angular velocity, and radius.
132 133 134 |
# File 'lib/joules/circular_motion.rb', line 132 def centripetal_force_v2(mass, angular_velocity, radius) return mass * (angular_velocity ** 2.0) * radius end |
.circle_area(radius) ⇒ Float
Calculates the area of a circle given radius.
96 97 98 |
# File 'lib/joules/geometry.rb', line 96 def circle_area(radius) return Math::PI * (radius ** 2) end |
.circumference(radius) ⇒ Float
Calculates the circumference of a circle given radius.
40 41 42 |
# File 'lib/joules/geometry.rb', line 40 def circumference(radius) return 2 * Math::PI * radius end |
.cone_surface_area(radius, slant_height) ⇒ Float
Calculates the surface area of a cone given radius and slant height.
165 166 167 |
# File 'lib/joules/geometry.rb', line 165 def cone_surface_area(radius, slant_height) return circle_area(radius) + (Math::PI * radius * slant_height) end |
.cone_volume(radius, height) ⇒ Float
Calculates the volume of a cone given radius and height.
124 125 126 |
# File 'lib/joules/geometry.rb', line 124 def cone_volume(radius, height) return (circle_area(radius) * height) / 3 end |
.current_v1(charge, time) ⇒ Float
There is one other method for calculating current.
Calculates the current given charge and time.
27 28 29 30 31 32 33 |
# File 'lib/joules/electricity.rb', line 27 def current_v1(charge, time) if time.zero? raise ZeroDivisionError.new('divided by 0') else return charge / time.to_f end end |
.current_v2(cross_sectional_area, charge_density, drift_velocity, charge) ⇒ Float
There is one other method for calculating current.
Calculates the current given cross sectional area, charge density, drift velocity, and charge.
49 50 51 |
# File 'lib/joules/electricity.rb', line 49 def current_v2(cross_sectional_area, charge_density, drift_velocity, charge) return cross_sectional_area * charge_density * drift_velocity * charge end |
.cylinder_surface_area(radius, height) ⇒ Float
Calulates the surface area of a cylinder given radius and height.
178 179 180 |
# File 'lib/joules/geometry.rb', line 178 def cylinder_surface_area(radius, height) return circumference(radius) * height end |
.cylinder_volume(radius, height) ⇒ Float
Calculates the volume of a cylinder given radius and height.
137 138 139 |
# File 'lib/joules/geometry.rb', line 137 def cylinder_volume(radius, height) return circle_area(radius) * height end |
.decay_constant(half_life) ⇒ Float
Calculates the decay constant of a decaying quantity given half-life.
63 64 65 66 67 68 69 |
# File 'lib/joules/quantum.rb', line 63 def decay_constant(half_life) if half_life.zero? raise ZeroDivisionError.new('divided by 0') else return Math.log(2) / half_life end end |
.density(mass, volume) ⇒ Float
Calculates the density given mass and volume.
26 27 28 29 30 31 32 |
# File 'lib/joules/density.rb', line 26 def density(mass, volume) if volume.zero? raise ZeroDivisionError.new('divided by 0') else return mass / volume.to_f end end |
.displacement_v1(initial_velocity, final_velocity, time) ⇒ Float
There are two other methods for calculating displacement.
Calculates the displacement given initial velocity, final velocity, and time.
116 117 118 |
# File 'lib/joules/kinematics.rb', line 116 def displacement_v1(initial_velocity, final_velocity, time) return 0.5 * (initial_velocity + final_velocity) * time end |
.displacement_v2(initial_velocity, acceleration, time) ⇒ Float
There are two other methods for calculating displacement.
Calculates the displacement given initial velocity, acceleration, and time.
132 133 134 |
# File 'lib/joules/kinematics.rb', line 132 def displacement_v2(initial_velocity, acceleration, time) return (initial_velocity * time) + (0.5 * acceleration * (time ** 2)) end |
.displacement_v3(final_velocity, acceleration, time) ⇒ Float
There are two other methods for calculating displacement.
Calculates the displacement given final velocity, acceleration, and time.
148 149 150 |
# File 'lib/joules/kinematics.rb', line 148 def displacement_v3(final_velocity, acceleration, time) return (final_velocity * time) - (0.5 * acceleration * (time ** 2)) end |
.elastic_potential_energy(spring_constant, extension) ⇒ Float
Calculates the elastic potential energy given spring constant and extension.
38 39 40 |
# File 'lib/joules/energy_work_power.rb', line 38 def elastic_potential_energy(spring_constant, extension) return 0.5 * spring_constant * (extension ** 2) end |
.electric_field_strength_v1(voltage, distance) ⇒ Float
There are two other method for calculating electric field strength.
Calculates the electric field strength given voltage and distance between two plates.
27 28 29 30 31 32 33 |
# File 'lib/joules/electric_fields.rb', line 27 def electric_field_strength_v1(voltage, distance) if distance.zero? raise ZeroDivisionError.new('divided by 0') else return voltage / distance.to_f end end |
.electric_field_strength_v2(force, charge) ⇒ Float
There are two other method for calculating electric field strength.
Calculates the electric field strength for an uniform field given force and charge.
46 47 48 49 50 51 52 |
# File 'lib/joules/electric_fields.rb', line 46 def electric_field_strength_v2(force, charge) if charge.zero? raise ZeroDivisionError.new('divided by 0') else return force / charge.to_f end end |
.electric_field_strength_v3(charge, distance) ⇒ Float
There are two other method for calculating electric field strength.
Calculates the electric field strength for a radial field given charge and distance.
65 66 67 68 69 70 71 |
# File 'lib/joules/electric_fields.rb', line 65 def electric_field_strength_v3(charge, distance) if distance.zero? raise ZeroDivisionError.new('divided by 0') else return charge / (4 * Math::PI * FREE_SPACE_PERMITTIVITY * (distance ** 2)) end end |
.electric_potential(charge, distance) ⇒ Float
Calculates the electric potential given charge and distance.
83 84 85 86 87 88 89 |
# File 'lib/joules/electric_fields.rb', line 83 def electric_potential(charge, distance) if distance.zero? raise ZeroDivisionError.new('divided by 0') else return charge / (4 * Math::PI * FREE_SPACE_PERMITTIVITY * distance) end end |
.energy_efficiency(useful_energy_output, energy_input) ⇒ Float
Calculates the energy efficiency given useful energy output and energy input.
116 117 118 119 120 121 122 |
# File 'lib/joules/energy_work_power.rb', line 116 def energy_efficiency(useful_energy_output, energy_input) if energy_input.zero? raise ZeroDivisionError.new('divided by 0') else return (useful_energy_output / energy_input.to_f) * 100 end end |
.energy_v1(mass, specific_heat_capacity, temperature_change) ⇒ Float
There are two other methods for calculating energy.
Calculates the energy given mass, specific heat capacity, and temperature change.
28 29 30 |
# File 'lib/joules/thermodynamics.rb', line 28 def energy_v1(mass, specific_heat_capacity, temperature_change) return mass * specific_heat_capacity * temperature_change.to_f end |
.energy_v2(mass, specific_latent_heat) ⇒ Float
There are two other methods for calculating energy.
Calculates the energy given mass and specific latent heat.
42 43 44 |
# File 'lib/joules/thermodynamics.rb', line 42 def energy_v2(mass, specific_latent_heat) return mass * specific_latent_heat.to_f end |
.energy_v3(voltage, current, time) ⇒ Float
There are two other methods for calculating energy.
Calculates the energy given voltage, current, and time.
318 319 320 |
# File 'lib/joules/electricity.rb', line 318 def energy_v3(voltage, current, time) return power_v2(voltage, current) * time end |
.energy_v4(mass) ⇒ Float
There are three other methods for calculating energy.
Calculates the energy given mass.
35 36 37 |
# File 'lib/joules/quantum.rb', line 35 def energy_v4(mass) return mass * (SPEED_OF_LIGHT ** 2) end |
.final_velocity_v1(initial_velocity, acceleration, time) ⇒ Float
There is one other method for calculating final velocity.
Calculates the final velocity given initial velocity, acceleration, and time.
84 85 86 |
# File 'lib/joules/kinematics.rb', line 84 def final_velocity_v1(initial_velocity, acceleration, time) return initial_velocity + (acceleration * time.to_f) end |
.final_velocity_v2(initial_velocity, acceleration, displacement) ⇒ Float
There is one other method for calculating final velocity.
Calculates the final velocity given initial velocity, acceleration, and displacement.
100 101 102 |
# File 'lib/joules/kinematics.rb', line 100 def final_velocity_v2(initial_velocity, acceleration, displacement) return ((initial_velocity ** 2) + (2 * acceleration * displacement)) ** 0.5 end |
.focal_length(object_distance, image_distance) ⇒ Float
Calculates the focal length of a lens given object distance and image distance.
163 164 165 166 167 168 169 |
# File 'lib/joules/waves.rb', line 163 def focal_length(object_distance, image_distance) if object_distance.zero? || image_distance.zero? raise ZeroDivisionError.new('divided by 0') else return 1 / ((1.0 / object_distance) + (1.0 / image_distance)) end end |
.force_v1(mass, acceleration) ⇒ Float
There are two other methods for calculating force.
Calculates the force given mass and acceleration.
26 27 28 |
# File 'lib/joules/forces.rb', line 26 def force_v1(mass, acceleration) return mass * acceleration.to_f end |
.force_v2(spring_constant, extension) ⇒ Float
There are two other methods for calculating force.
Calculates the force given spring constant and extension.
40 41 42 |
# File 'lib/joules/forces.rb', line 40 def force_v2(spring_constant, extension) return spring_constant * extension.to_f end |
.force_v3(initial_velocity, final_velocity, mass, time) ⇒ Float
There are two other methods for calculating force.
Calculates the force given initial velocity, final velocity, mass, and time.
59 60 61 62 63 64 65 |
# File 'lib/joules/forces.rb', line 59 def force_v3(initial_velocity, final_velocity, mass, time) if time.zero? raise ZeroDivisionError.new('divided by 0') else return ((final_velocity - initial_velocity) * mass) / time.to_f end end |
.frequency_v1(wave_speed, wavelength) ⇒ Float
There is one other method for calculating frequency.
Calculates the frequency given wave speed and wavelength.
58 59 60 61 62 63 64 |
# File 'lib/joules/waves.rb', line 58 def frequency_v1(wave_speed, wavelength) if wavelength.zero? raise ZeroDivisionError.new('divided by 0') else return wave_speed / wavelength.to_f end end |
.frequency_v2(time_period) ⇒ Float
There is one other method for calculating frequency.
Calculates the frequency given time period.
75 76 77 78 79 80 81 |
# File 'lib/joules/waves.rb', line 75 def frequency_v2(time_period) if time_period.zero? raise ZeroDivisionError.new('divided by 0') else return 1.0 / time_period end end |
.gravitational_field_strength_v1(force, mass) ⇒ Float
There is one other method for calculating gravitational field strength.
Calculates the gravitational field strength given force and mass.
48 49 50 51 52 53 54 |
# File 'lib/joules/gravitational_fields.rb', line 48 def gravitational_field_strength_v1(force, mass) if mass.zero? raise ZeroDivisionError.new('divided by 0') else return force / mass.to_f end end |
.gravitational_field_strength_v2(mass, distance) ⇒ Float
There is one other method for calculating gravitational field strength.
Calculates the gravitational field strength given mass and distance.
67 68 69 70 71 72 73 |
# File 'lib/joules/gravitational_fields.rb', line 67 def gravitational_field_strength_v2(mass, distance) if distance.zero? raise ZeroDivisionError.new('divided by 0') else return (GRAVITATIONAL_CONSTANT * mass) / (distance ** 2) end end |
.gravitational_force(object_mass1, object_mass2, distance) ⇒ Float
Calculates the gravitational force given object mass 1, object mass 2, and distance between the centres of the two objects.
28 29 30 31 32 33 34 35 |
# File 'lib/joules/gravitational_fields.rb', line 28 def gravitational_force(object_mass1, object_mass2, distance) if distance.zero? raise ZeroDivisionError.new('divided by 0') else return (GRAVITATIONAL_CONSTANT * object_mass1 * object_mass2) / (distance ** 2) end end |
.gravitational_potential(mass, distance) ⇒ Float
Calculates the gravitational potential given mass and distance.
85 86 87 88 89 90 91 |
# File 'lib/joules/gravitational_fields.rb', line 85 def gravitational_potential(mass, distance) if distance.zero? raise ZeroDivisionError.new('divided by 0') else return (-GRAVITATIONAL_CONSTANT * mass) / distance end end |
.gravitational_potential_energy(mass, height) ⇒ Float
Calculates the gravitational potential energy given mass and height.
25 26 27 |
# File 'lib/joules/energy_work_power.rb', line 25 def gravitational_potential_energy(mass, height) return mass * FREE_FALL_ACCELERATION * height end |
.half_life(decay_constant) ⇒ Float
Calculates the half-life of a decaying quantity given decay constant.
47 48 49 50 51 52 53 |
# File 'lib/joules/quantum.rb', line 47 def half_life(decay_constant) if decay_constant.zero? raise ZeroDivisionError.new('divided by 0') else return Math.log(2) / decay_constant end end |
.hydrostatic_pressure(density, height) ⇒ Float
Calculates the hydrostatic pressure given density and height.
43 44 45 |
# File 'lib/joules/pressure.rb', line 43 def hydrostatic_pressure(density, height) return density * FREE_FALL_ACCELERATION * height end |
.impulse_v1(force, time) ⇒ Float
There is one other method for calculating impulse.
Calculates the impulse given force and time.
39 40 41 |
# File 'lib/joules/momentum_impulse.rb', line 39 def impulse_v1(force, time) return force * time.to_f end |
.impulse_v2(initial_velocity, final_velocity, mass) ⇒ Float
There is one other method for calculating impulse.
Calculates the impulse given initial velocity, final velocity, and mass.
55 56 57 |
# File 'lib/joules/momentum_impulse.rb', line 55 def impulse_v2(initial_velocity, final_velocity, mass) return (final_velocity - initial_velocity) * mass.to_f end |
.kinetic_energy_v1(mass, velocity) ⇒ Float
There is one other method for calculating kinetic energy.
Calculates the kinetic energy given mass and velocity.
52 53 54 |
# File 'lib/joules/energy_work_power.rb', line 52 def kinetic_energy_v1(mass, velocity) return 0.5 * mass * (velocity ** 2) end |
.kinetic_energy_v2(voltage, charge) ⇒ Float
There is one other method for calculating kinetic energy.
Calculates the kinetic energy of an electron given voltage.
101 102 103 |
# File 'lib/joules/electric_fields.rb', line 101 def kinetic_energy_v2(voltage, charge) return voltage * (charge / ELEMENTARY_CHARGE) end |
.magnetic_flux(flux_density, area, angle = 0) ⇒ Float
Calculates the magnetic flux given flux density, area, and angle.
63 64 65 |
# File 'lib/joules/magnetic_fields.rb', line 63 def magnetic_flux(flux_density, area, angle = 0) return flux_density * area * Math.cos(to_radians(angle)) end |
.magnetic_flux_linkage(magnetic_flux, number_of_coils) ⇒ Float
Calculates the magnetic flux linkage given magnetic flux and number of coils in the wire.
76 77 78 |
# File 'lib/joules/magnetic_fields.rb', line 76 def magnetic_flux_linkage(magnetic_flux, number_of_coils) return magnetic_flux * number_of_coils.to_f end |
.magnetic_force_v1(flux_density, current, conductor_length, angle = 90) ⇒ Float
There is one other method for calculating magnetic force.
Calculates the magnetic force on a current given flux density, current, conductor length, and angle.
30 31 32 |
# File 'lib/joules/magnetic_fields.rb', line 30 def magnetic_force_v1(flux_density, current, conductor_length, angle = 90) return flux_density * current * conductor_length * Math.sin(to_radians(angle)) end |
.magnetic_force_v2(flux_density, charge, velocity, angle = 90) ⇒ Float
There is one other method for calculating magnetic force.
Calculates the magnetic force on a moving charge given flux density, charge, velocity, and angle.
48 49 50 |
# File 'lib/joules/magnetic_fields.rb', line 48 def magnetic_force_v2(flux_density, charge, velocity, angle = 90) return flux_density * charge * velocity * Math.sin(to_radians(angle)) end |
.magnification(image_height, object_height) ⇒ Float
Calculates the magnification given image height and object height.
145 146 147 148 149 150 151 |
# File 'lib/joules/waves.rb', line 145 def magnification(image_height, object_height) if object_height.zero? raise ZeroDivisionError.new('divided by 0') else return image_height / object_height.to_f end end |
.mass(weight) ⇒ Float
Calculates the mass given weight.
34 35 36 |
# File 'lib/joules/mass_weight.rb', line 34 def mass(weight) return weight / FREE_FALL_ACCELERATION end |
.max_particle_acceleration(angular_velocity, amplitude) ⇒ Float
Calculates the maximum acceleration of a particle in oscillation given angular velocity and amplitude.
91 92 93 |
# File 'lib/joules/oscillations.rb', line 91 def max_particle_acceleration(angular_velocity, amplitude) return (angular_velocity ** 2.0) * amplitude end |
.max_particle_speed(angular_velocity, amplitude) ⇒ Float
Calculates the maximum speed of a particle in oscillation given angular velocity and amplitude.
78 79 80 |
# File 'lib/joules/oscillations.rb', line 78 def max_particle_speed(angular_velocity, amplitude) return angular_velocity * amplitude.to_f end |
.maximum_friction_force(coefficient_of_friction, normal_force) ⇒ Float
Calculates the maximum friction force given coefficient of friction and normal force.
76 77 78 |
# File 'lib/joules/forces.rb', line 76 def maximum_friction_force(coefficient_of_friction, normal_force) return coefficient_of_friction * normal_force.to_f end |
.moment(force, distance, angle = 90) ⇒ Float
Calculates the moment given force, distance, and angle.
104 105 106 |
# File 'lib/joules/forces.rb', line 104 def moment(force, distance, angle = 90) return force * distance * Math.sin(to_radians(angle)) end |
.momentum(mass, velocity) ⇒ Float
Calculates the momentum given mass and velocity.
25 26 27 |
# File 'lib/joules/momentum_impulse.rb', line 25 def momentum(mass, velocity) return mass * velocity.to_f end |
.particle_acceleration(angular_velocity, particle_displacement) ⇒ Float
There is one other method for calculating acceleration.
Calculates the acceleration of a particle in oscillation given angular velocity and particle displacement.
26 27 28 |
# File 'lib/joules/oscillations.rb', line 26 def particle_acceleration(angular_velocity, particle_displacement) return (- (angular_velocity ** 2.0) * displacement) end |
.particle_displacement(amplitude, angular_velocity, time) ⇒ Float
Calculates the displacement of a particle in oscillation given amplitude, angular velocity, and time.
41 42 43 |
# File 'lib/joules/oscillations.rb', line 41 def particle_displacement(amplitude, angular_velocity, time) return amplitude * Math.cos(angular_velocity * time) end |
.particle_velocity(angular_velocity, amplitude, particle_displacement, return_sign = nil) ⇒ Float+
Calculates the velocity of a particle in oscillation given angular velocity, amplitude, and particle displacement.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/joules/oscillations.rb', line 58 def particle_velocity(angular_velocity, amplitude, particle_displacement, return_sign = nil) return_value = angular_velocity * (((amplitude ** 2) - (particle_displacement ** 2)) ** 0.5) if return_sign == '-' return (- return_value) elsif return_sign == '+' return return_value else return [return_value, (- return_value)] end end |
.photon_energy(frequency) ⇒ Float
Calculates the photon energy given frequency.
23 24 25 |
# File 'lib/joules/quantum.rb', line 23 def photon_energy(frequency) return PLANCK_CONSTANT * frequency end |
.power_efficiency(useful_power_output, power_input) ⇒ Float
Calculates the power efficiency given useful power output and power input.
134 135 136 137 138 139 140 |
# File 'lib/joules/energy_work_power.rb', line 134 def power_efficiency(useful_power_output, power_input) if power_input.zero? raise ZeroDivisionError.new('divided by 0') else return (useful_power_output / power_input.to_f) * 100 end end |
.power_of_lens(focal_length) ⇒ Float
Calculates the power of a lens given focal length.
179 180 181 182 183 184 185 |
# File 'lib/joules/waves.rb', line 179 def power_of_lens(focal_length) if focal_length.zero? raise ZeroDivisionError.new('divided by 0') else return 1.0 / focal_length end end |
.power_v1(work_done, time) ⇒ Float
There are four other methods for calculating power.
Calculates the power given work done and time.
82 83 84 85 86 87 88 |
# File 'lib/joules/energy_work_power.rb', line 82 def power_v1(work_done, time) if time.zero? raise ZeroDivisionError.new('divided by 0') else return work_done / time.to_f end end |
.power_v2(force, velocity, angle = 0) ⇒ Float
There are four other methods for calculating power.
Calculates the power given force, velocity, and angle.
102 103 104 |
# File 'lib/joules/energy_work_power.rb', line 102 def power_v2(force, velocity, angle = 0) return force * velocity * Math.cos(to_radians(angle)) end |
.power_v3(voltage, current) ⇒ Float
There are four other methods for calculating power.
Calculates the power given voltage and current.
269 270 271 |
# File 'lib/joules/electricity.rb', line 269 def power_v3(voltage, current) return voltage * current.to_f end |
.power_v4(current, resistance) ⇒ Float
There are four other methods for calculating power.
Calculates the power given current and resistance.
283 284 285 |
# File 'lib/joules/electricity.rb', line 283 def power_v4(current, resistance) return (current ** 2.0) * resistance end |
.power_v5(voltage, resistance) ⇒ Float
There are four other methods for calculating power.
Calculates the power given voltage and resistance.
298 299 300 301 302 303 304 |
# File 'lib/joules/electricity.rb', line 298 def power_v5(voltage, resistance) if resistance.zero? raise ZeroDivisionError.new('divided by 0') else return (voltage ** 2.0) / resistance end end |
.pressure(force, area) ⇒ Float
Calculates the pressure given force and area.
26 27 28 29 30 31 32 |
# File 'lib/joules/pressure.rb', line 26 def pressure(force, area) if area.zero? raise ZeroDivisionError.new('divided by 0') else return force / area.to_f end end |
.rectangle_area(length, width) ⇒ Float
Calculates the area of a rectangle given length and width.
85 86 87 |
# File 'lib/joules/geometry.rb', line 85 def rectangle_area(length, width) return length * width.to_f end |
.refractive_index_v1(angle_of_incidence, angle_of_refraction) ⇒ Float
There is one other method for calculating refractive index.
Calculates the refractive index of a substance given angle of incidence and angle of refraction.
110 111 112 113 114 115 116 117 |
# File 'lib/joules/waves.rb', line 110 def refractive_index_v1(angle_of_incidence, angle_of_refraction) if angle_of_refraction.zero? raise ZeroDivisionError.new('divided by 0') else return Math.sin(to_radians(angle_of_incidence)) / Math.sin(to_radians(angle_of_refraction)) end end |
.refractive_index_v2(critical_angle) ⇒ Float
There is one other method for calculating refractive index.
Calculates the refractive index of a substance given critical angle.
127 128 129 130 131 132 133 |
# File 'lib/joules/waves.rb', line 127 def refractive_index_v2(critical_angle) if critical_angle.zero? raise ZeroDivisionError.new('divided by 0') else return 1.0 / Math.sin(to_radians(critical_angle)) end end |
.resistance_in_parallel(resistances) ⇒ Float
Calculates the total resistance of resistors in parallel.
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/joules/electricity.rb', line 115 def resistance_in_parallel(resistances) total_resistance = 0 if resistances.empty? return total_resistance.to_f else resistances.each do |resistance| total_resistance += (1.0 / resistance) end return 1 / total_resistance end end |
.resistance_in_series(resistances) ⇒ Float
Calculates the total resistance of resistors in series.
100 101 102 103 104 105 106 |
# File 'lib/joules/electricity.rb', line 100 def resistance_in_series(resistances) total_resistance = 0 resistances.each do |resistance| total_resistance += resistance end return total_resistance.to_f end |
.resistance_v1(voltage, current) ⇒ Float
There is one other method for calculating resistance.
Calculates the resistance given voltage and current.
64 65 66 67 68 69 70 |
# File 'lib/joules/electricity.rb', line 64 def resistance_v1(voltage, current) if current.zero? raise ZeroDivisionError.new('divided by 0') else return voltage / current.to_f end end |
.resistance_v2(resistivity, wire_length, cross_sectional_area) ⇒ Float
There is one other method for calculating resistance.
Calculates the resistance given resistivity, wire length, and cross sectional area.
85 86 87 88 89 90 91 |
# File 'lib/joules/electricity.rb', line 85 def resistance_v2(resistivity, wire_length, cross_sectional_area) if cross_sectional_area.zero? raise ZeroDivisionError.new('divided by 0') else return (resistivity * wire_length) / cross_sectional_area.to_f end end |
.sphere_surface_area(radius) ⇒ Float
Calculates the surface area of a sphere given radius.
152 153 154 |
# File 'lib/joules/geometry.rb', line 152 def sphere_surface_area(radius) return 4 * circle_area(radius) end |
.sphere_volume(radius) ⇒ Float
Calculates the volume of a sphere given radius.
111 112 113 |
# File 'lib/joules/geometry.rb', line 111 def sphere_volume(radius) return (4 * circle_area(radius) * radius) / 3 end |
.tensile_strain(extension, length) ⇒ Float
Calculates the tensile strain given extension and length.
44 45 46 47 48 49 50 |
# File 'lib/joules/stress_strain.rb', line 44 def tensile_strain(extension, length) if length.zero? raise ZeroDivisionError.new('divided by 0') else return extension / length.to_f end end |
.tensile_stress(force, area) ⇒ Float
Calculates the tensile stress given force and area.
26 27 28 29 30 31 32 |
# File 'lib/joules/stress_strain.rb', line 26 def tensile_stress(force, area) if area.zero? raise ZeroDivisionError.new('divided by 0') else return force / area.to_f end end |
.time_period_v1(frequency) ⇒ Float
There are two other methods for calculating time period.
Calculates the time period given frequency.
92 93 94 95 96 97 98 |
# File 'lib/joules/waves.rb', line 92 def time_period_v1(frequency) if frequency.zero? raise ZeroDivisionError.new('divided by 0') else return 1.0 / frequency end end |
.time_period_v2(mass, spring_constant) ⇒ Float
There are two other methods for calculating time period.
Calculates the time period of a mass-spring system given mass and spring constant.
106 107 108 109 110 111 112 |
# File 'lib/joules/oscillations.rb', line 106 def time_period_v2(mass, spring_constant) if spring_constant.zero? raise ZeroDivisionError.new('divided by 0') else return 2 * Math::PI * ((mass / spring_constant.to_f) ** 0.5) end end |
.time_period_v3(pendulum_length) ⇒ Float
There are two other methods for calculating time period.
Calculates the time period of a simple pendulum given pendulum length.
122 123 124 |
# File 'lib/joules/oscillations.rb', line 122 def time_period_v3(pendulum_length) return 2 * Math::PI * ((pendulum_length / FREE_FALL_ACCELERATION) ** 0.5) end |
.to_celcius(temperature) ⇒ Float
Calculates the equivalent temperature in celcius given kelvins.
60 61 62 |
# File 'lib/joules/conversion.rb', line 60 def to_celcius(temperature) return temperature - 273.15 end |
.to_degrees(angle) ⇒ Float
Calculates the equivalent angle in degrees given radians.
23 24 25 |
# File 'lib/joules/conversion.rb', line 23 def to_degrees(angle) return (angle * 180) / Math::PI end |
.to_kelvins(temperature) ⇒ Float
Calculates the equivalent temperature in kelvins given celcius.
49 50 51 |
# File 'lib/joules/conversion.rb', line 49 def to_kelvins(temperature) return temperature + 273.15 end |
.to_kilometres_per_hour(velocity) ⇒ Float
Calculates the equivalent velocity in kilometres per hour given metres per second.
86 87 88 |
# File 'lib/joules/conversion.rb', line 86 def to_kilometres_per_hour(velocity) return (velocity * 3600) / 1000.0 end |
.to_metres_per_second(velocity) ⇒ Float
Calculates the equivalent velocity in metres per second given kilometres per hour.
75 76 77 |
# File 'lib/joules/conversion.rb', line 75 def to_metres_per_second(velocity) return (velocity * 1000) / 3600.0 end |
.to_radians(angle) ⇒ Float
Calculates the equivalent angle in radians given degrees.
34 35 36 |
# File 'lib/joules/conversion.rb', line 34 def to_radians(angle) return (angle * Math::PI) / 180 end |
.trapezium_area(top_base, bottom_base, height) ⇒ Float
Calculates the area of a trapezium given top base, bottom base, and height.
72 73 74 |
# File 'lib/joules/geometry.rb', line 72 def trapezium_area(top_base, bottom_base, height) return 0.5 * (top_base + bottom_base) * height end |
.triangle_area(base, height) ⇒ Float
Calculates the area of a triangle given base and height.
57 58 59 |
# File 'lib/joules/geometry.rb', line 57 def triangle_area(base, height) return 0.5 * base * height end |
.voltage_v1(energy, charge) ⇒ Float
There is one other method for calculating voltage.
Calculates the voltage given energy and charge.
237 238 239 240 241 242 243 |
# File 'lib/joules/electricity.rb', line 237 def voltage_v1(energy, charge) if charge.zero? raise ZeroDivisionError.new('divided by 0') else return energy / charge.to_f end end |
.voltage_v2(current, resistance) ⇒ Float
There is one other method for calculating voltage.
Calculates the voltage given current and resistance.
255 256 257 |
# File 'lib/joules/electricity.rb', line 255 def voltage_v2(current, resistance) return current * resistance.to_f end |
.wave_speed(frequency, wavelength) ⇒ Float
Calculates the wave speed given frequency and wavelength.
25 26 27 |
# File 'lib/joules/waves.rb', line 25 def wave_speed(frequency, wavelength) return frequency * wavelength.to_f end |
.wavelength(wave_speed, frequency) ⇒ Float
Calculates the wavelength given wave speed and frequency.
39 40 41 42 43 44 45 |
# File 'lib/joules/waves.rb', line 39 def wavelength(wave_speed, frequency) if frequency.zero? raise ZeroDivisionError.new('divided by 0') else return wave_speed / frequency.to_f end end |
.weight(mass) ⇒ Float
Calculates the weight given mass.
23 24 25 |
# File 'lib/joules/mass_weight.rb', line 23 def weight(mass) return mass * FREE_FALL_ACCELERATION end |
.work_done(force, displacement, angle = 0) ⇒ Float
Calculates the work done given force, displacement, and angle.
67 68 69 |
# File 'lib/joules/energy_work_power.rb', line 67 def work_done(force, displacement, angle = 0) return force * displacement * Math.cos(to_radians(angle)) end |
.young_modulus(tensile_stress, tensile_strain) ⇒ Float
Calculates the Young modulus given tensile stress and tensile strain.
62 63 64 65 66 67 68 |
# File 'lib/joules/stress_strain.rb', line 62 def young_modulus(tensile_stress, tensile_strain) if tensile_strain.zero? raise ZeroDivisionError.new('divided by 0') else return tensile_stress / tensile_strain.to_f end end |