area_crate

Crates.ioarea_crate
lib.rsarea_crate
version0.1.1
sourcesrc
created_at2023-08-10 10:45:37.614802
updated_at2024-06-15 12:30:59.995243
descriptionBasic Area function
homepage
repository
max_upload_size
id940823
size7,130
Akshit Vadodariya (AkshitVadodariya1201)

documentation

README

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)
}
Commit count: 0

cargo fmt