module Diorite::MathHelpers

Overview

Pure mathematical utilities and vector transformations for debug geometry generation.

Direct including types

Defined in:

diorite/core/math_helpers.cr

Constant Summary

PI = 3.14159265358979323846_f32

Standard circle constant PI (π).

TAU = 6.28318530717958647692_f32

Circle constant TAU (2π), representing one full turn in radians.

Class Method Summary

Class Method Detail

def self.deg_to_rad(degrees : Number) : Float32 #

Converts an angle from degrees to radians.


[View source]
def self.find_perpendicular(normal : Godot::Vector3) : Godot::Vector3 #

Finds a perpendicular unit vector to the given normalized vector normal.

Avoids gimbal singularities by checking alignment with coordinate axes.

norm = Vector3.new(0, 1, 0)
perp = MathHelpers.find_perpendicular(norm)

[View source]
def self.orthonormal_plane(normal : Godot::Vector3) : Tuple(Godot::Vector3, Godot::Vector3) #

Constructs an orthonormal basis (u, v) spanning the plane perpendicular to normal.

Both vectors are unit length and orthogonal to each other and to normal.

u, v = MathHelpers.orthonormal_plane(surface_normal)

[View source]
def self.rad_to_deg(radians : Number) : Float32 #

Converts an angle from radians to degrees.


[View source]
def self.rotate_around_axis(point : Godot::Vector3, axis : Godot::Vector3, theta : Float32) : Godot::Vector3 #

Rotates a 3D point around an arbitrary axis by theta radians using Rodrigues' formula.

rotated = MathHelpers.rotate_around_axis(pt, Vector3.new(0, 1, 0), Math::PI / 2)

[View source]