Skip to content

HaraldWik/numz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

numz

A linear algebra math lib for Zig

Installation

zig fetch --save git+https://github.com/HaraldWik/numz
const numz_mod = b.dependency("numz", .{
    .target = target,
    .optimize = optimize,
}).module("numz");
// How I recommend making the import
const nz = @import("numz");

pub fn main() !void {
    const mat: nz.Mat4x4(f32) = .identity;
    const a: nz.Vec3(f32) = .{ 1, 2, 3 };
    const b: nz.Vec3(f32) = .{ 3, 2, 1 };

    const result = a + b; // They are SIMD which makes them support operations and some functions like @abs

    const arr = [3]f32{0, 1, 2};

    _ = nz.vec.normalize(arr); // All vector functions also support array vectors

    const c: nz.Vec2(u32) = undefined; // Support for Vec2
    const d: nz.Vec4(u32) = undefined; // Support for Vec4
    const e: @Vector(3, f32) = .{ 1, 2, 3 }; // Optioanly you can use this style
}

Vectors

  • Vec2
  • Vec3
  • Vec4

Functions

  • eql
  • scale
  • dot
  • cross
  • length
  • normalize
  • negate
  • distance
  • distanceSquared
  • reflect
  • mix
  • forward
  • forwardFromEuler

Matrices

  • Mat4x4 <-- Column mayor so it works with OpenGL and Vulkan

Functions

  • new
  • identity
  • mul
  • translate
  • scale
  • rotate Standard Rodrigues’ rotation
  • perspective
  • orthographic
  • crossProduct3D
  • lookAt
  • transpose
  • inverse
  • fromQuaternion

Quaternions

  • Normal idk // This will change a lot

Functions

  • identity
  • new
  • mul
  • conjugate
  • fromEuler
  • toEuler

Note: The quaternions are under development, I do not recommend using this math library if you really need quaternion

Transform

  • 3D
  • 2D

Functions

  • toMat4x4

Colors

  • Rgb
  • Rgba

Functions

  • new
  • eql
  • alpha
  • from
  • to
  • fromVec
  • toVec
  • fromHex
  • toU32

Constants

  • len
  • max
  • min
  • white
  • black
  • red
  • green
  • blue

Feature requests

Feel free to make feature requests; I always want to know what can be improved.

But I won’t create hyper-specific features, nor will I implement algorithms.

Planned features

  • More and better quaternion types
  • Mat3x3
  • Mat2x2

This math lib is tested in

About

A linear algebra math lib for zig

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages