mdmath_core

Crates.iomdmath_core
lib.rsmdmath_core
version0.2.0
sourcesrc
created_at2024-09-17 09:37:49.49271
updated_at2024-10-28 11:01:38.191572
descriptionMultidimensional math, fundamental functionality and types.
homepage
repositoryhttps://github.com/Wandalen/cg_tools
max_upload_size
id1377273
size117,067
Wandalen (Wandalen)

documentation

README

mdmath_core

Fundamental functionality and types, representation slices and tuples as vectors.

Implemented Features

  • Vector:
    • Operations:
      • Dot product of two vectors.
      • Magnitude of the vector.
      • Normalizing the vector.
      • Projection on another vector.
      • Angle beetween two vectors.
      • Orthogonal checking between two vectors.
      • Dimension offset of the vector.
    • Mut/Unmut ref from slice and tuple.
    • Mut/Unmut iterators.

Installation

Add to your example [dependencies] in Cargo.toml configuration file:

mdmath_core = { workspace = true }

Examples

Dot product of two vectors

  let vec_a = [ 1.0, 2.0, 3.0 ];
  let vec_b = [ 4.0, 5.0, 6.0 ];
  let result = mdmath_core::vector::dot( &vec_a, &vec_b );
  assert_eq!( result, 32.0 );

Magnitude of the vector

  let vec_a = [ 1.0, 2.0, 3.0 ];
  let result = mdmath_core::vector::mag2( &vec_a );
  assert_ulps_eq!( result, 14.0 );

Normalizing the vector

  let vec_a = [ 3.0, 4.0 ];
  let mut result = vec_a.clone();
  mdmath_core::vector::normalize( &mut result, &vec_a );
  let expected = [ 0.6, 0.8 ];
  assert_eq!( result, expected );

Projection on another vector

  let mut vec_a = [ 1.0, 2.0, 3.0 ];
  let vec_b = [ 4.0, 5.0, 6.0 ];
  mdmath_core::vector::project_on( &mut vec_a, &vec_b );
  let expected = [ 1.6623376623376624, 2.077922077922078, 2.4935064935064934 ];
  assert_eq!( vec_a, expected );

Angle beetween two vectors

  let vec_a = [ 1.0, 0.0 ];
  let vec_b = [ 0.0, 1.0 ];
  let result = mdmath_core::vector::angle( &vec_a, &vec_b );
  assert_ulps_eq!( result, std::f32::consts::FRAC_PI_2 );

Orthogonal checking between two vectors

  let vec_a = [ 1.0, 0.0 ];
  let vec_b = [ 0.0, 1.0 ];
  assert!( mdmath_core::vector::is_orthogonal( &vec_a, &vec_b ), "Orthogonal test failed for orthogonal vectors" );
Commit count: 0

cargo fmt