L1A/math.cpp

56 lines
1.9 KiB
C++
Raw Normal View History

2024-08-28 22:29:28 -06:00
#include <cmath>
double const MOLAR_GAS_CONSTANT = 8.314'462'618'153'24;
double const GRAVITATIONAL_CONSTANT = 0.000'000'000'066'740'8;
double const SPHERE_VOLUME_RATIO = 4.0 / 3;
double const VACUUM_PERMITTIVITY = 0.000'000'000'008'854'187'818'8;
double ideal_gas_law(double moles, double gasAbsoluteTemperature,
double volume) {
return (moles * MOLAR_GAS_CONSTANT * gasAbsoluteTemperature) / volume;
}
double average_acceleration(double posStart, double posEnd, double timeStart,
double timeEnd) {
return (posEnd - posStart) / std::pow(timeEnd - timeStart, 2);
}
double ohms_law(double voltage, double resistance) {
return voltage / resistance;
}
double universal_gravitation(double massOne, double massTwo, double distance) {
return GRAVITATIONAL_CONSTANT * ((massOne * massTwo) / std::pow(distance, 2));
}
double pythagorean_theorem(double x, double y) {
return std::sqrt(std::pow(x, 2) + std::pow(y, 2));
}
double sphere_volume(double radius) {
return SPHERE_VOLUME_RATIO * M_PI * std::pow(radius, 3);
}
double deflection(double weight, double length, double elasticityModulus,
double momentOfInertia) {
return (weight * std::pow(length, 3)) /
(3 * elasticityModulus * momentOfInertia);
}
double heat_transfer_rate(double transferCoefficient, double surfaceArea,
double temperatureChange) {
return transferCoefficient * surfaceArea * temperatureChange;
}
double stress(double force, double area) { return force / area; }
double shear_stress(double sigmaX, double sigmaY, double tauXY, double theta) {
return -0.5 * (sigmaX - sigmaY) * sin(2 * theta) + tauXY * cos(2 * theta);
}
double coulombs_law(double charge1, double charge2,
double relativeStaticPermittivity, double distance) {
return std::fabs(charge1 * charge2) /
(4 * M_PI * VACUUM_PERMITTIVITY * relativeStaticPermittivity *
std::pow(distance, 2));
}