2 releases
0.1.1 | Jun 15, 2024 |
---|---|
0.1.0 | Aug 10, 2023 |
#375 in Math
77 downloads per month
7KB
Basic Area Crate
This is a collection of some generally used area functions.
Find the Area
Example
Area of Circle
let radius = 12.0;
let answer = area_crate::area::circle(radius);
assert_eq!(452.38934211696005, answer);
Functions
Circle Area
pub fn circle(radius: f64) -> f64 {
let pi = 3.14159265359;
pi * radius * radius
}
Triangle Area
pub fn triangle(base: f64, height: f64) -> f64 {
0.5 * base * height
}
Rectangle Area
pub fn rectangle(length: f64, breadth: f64) -> f64 {
length * breadth
}
Square Area
pub fn square(side: f64) -> f64 {
side * side
}
Parallelogram Area
pub fn parallelogram(base: f64, height: f64) -> f64 {
base * height
}
Trapezoid Area
pub fn trapezoid(base1: f64, base2: f64, height: f64) -> f64 {
0.5 * (base1 + base2) * height
}
Ellipse Area
pub fn ellipse(major_axis: f64, minor_axis: f64) -> f64 {
let pi = 3.14159265359;
pi * major_axis * minor_axis
}
Sector Area
pub fn sector(radius: f64, angle: f64) -> f64 {
let pi = 3.14159265359;
0.5 * radius * radius * angle.to_radians()
}
Rhombus Area
pub fn rhombus(diagonal1: f64, diagonal2: f64) -> f64 {
0.5 * diagonal1 * diagonal2
}
Kite Area
pub fn kite(diagonal1: f64, diagonal2: f64) -> f64 {
0.5 * diagonal1 * diagonal2
}
Regular Polygon Area
pub fn regular_polygon(perimeter: f64, apothem: f64) -> f64 {
0.5 * perimeter * apothem
}
Annulus Area
pub fn annulus(outer_radius: f64, inner_radius: f64) -> f64 {
let pi = 3.14159265359;
pi * (outer_radius * outer_radius - inner_radius * inner_radius)
}