Crates.io | goniometry |
lib.rs | goniometry |
version | 0.1.0 |
source | src |
created_at | 2024-11-17 00:17:58.891464 |
updated_at | 2024-11-17 00:17:58.891464 |
description | A simple Rust module for working with trigonometric functions like sine, cosine, tangent and much more to come. |
homepage | |
repository | https://github.com/zerootoad/Rust-Goniometry |
max_upload_size | |
id | 1450742 |
size | 44,194 |
A simple Rust library for performing goniometry operations (trigonometric functions like sine, cosine, tangent) and handling angle metrics (degrees and radians). This library allows you to define angles using values or fractions for greater precision, making it easy to calculate trigonometric values and convert between degrees and radians.
sin
, cos
, and tan
for computing sine, cosine, and tangent of angles.Add the following to your Cargo.toml
file to include this library as a dependency (or clone the repository if you prefer):
[dependencies]
goniometry = "*"
Here’s how you can use the library in your own project:
use goniometry::functions::*;
use goniometry::metrics::{Degree, Rad, Metric, MetricEntry};
fn main() {
// Create a Rad object with a fraction
let rad = Rad::new(MetricEntry::Fraction(1, 2));
println!("Rad1 (fraction): {}", rad);
// Create a Rad object with the default value (π)
let drad = Rad::default();
println!("Rad2 (default): {}", drad);
// Create a Degree object with a specific value
let deg = Degree::new(MetricEntry::Value(90));
println!("Deg1 (value): {}", deg);
// Create a Degree object with the default value (180)
let ddeg = Degree::default();
println!("Deg2 (default): {}", ddeg);
// Calculate trigonometric functions for Degree input
let sen = sin(deg);
println!("sin of Deg1: {}", sen);
let cos = cos(ddeg);
println!("cos of Deg2: {}", cos);
let tan = tan(Degree::new(MetricEntry::Value(36)));
println!("tan of 36 degrees: {}", tan);
}
The library provides the following trigonometric functions that accept either Degree
or Rad
objects:
sin(angle)
– Calculates the sine of the angle.cos(angle)
– Calculates the cosine of the angle.tan(angle)
– Calculates the tangent of the angle.The library supports two types of angle metrics:
The Rad
struct supports both value-based and fraction-based angle definitions. For example, you can create a radian value using a fraction like π/2
(Fraction(1, 2)).
The Degree
struct allows you to specify angles directly in degrees.
You can create angles using specific values or fractions:
let rad = Rad::new(MetricEntry::Fraction(1, 2)); // π/2 radians
let deg = Degree::new(MetricEntry::Value(90)); // 90 degrees
You can calculate trigonometric values for angles in either radians or degrees:
let sine_value = sin(Degree::new(MetricEntry::Value(45))); // sin(45 degrees)
let cosine_value = cos(Rad::new(MetricEntry::Fraction(1, 2))); // cos(π/2 radians)
let tangent_value = tan(Degree::new(MetricEntry::Value(36))); // tan(36 degrees)
You can install this library in your project by adding it as a dependency in Cargo.toml
or by cloning the repository.
Clone the repository:
git clone https://github.com/your-username/goniometry.git
This project is licensed under the GNU License. See the LICENSE file for more details.