### Installation via NuGet Package Manager in Bash Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md Provides the command-line instruction to install the FixedMathSharp library using the .NET NuGet package manager. This is the recommended method for integrating the library into non-Unity .NET projects. ```bash dotnet add package FixedMathSharp ``` -------------------------------- ### Quaternion Rotation Example in C# Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md Shows how to use `FixedQuaternion` for rotations, demonstrating rotation around an axis and applying it to a point. This is crucial for smooth, gimbal-lock-free rotations in 3D applications. ```csharp FixedQuaternion rotation = FixedQuaternion.FromAxisAngle(Vector3d.Up, FixedMath.PiOver2); // 90 degrees around Y-axis Vector3d point = new Vector3d(1, 0, 0); Vector3d rotatedPoint = rotation.Rotate(point); Console.WriteLine(rotatedPoint); // Output: (0, 0, -1) ``` -------------------------------- ### DeterministicRandom Generation with FixedMathSharp Source: https://context7.com/mrdav30/fixedmathsharp/llms.txt Demonstrates creating a DeterministicRandom instance with a seed and generating various types of random numbers, including integers, doubles, Fixed64 values, and byte arrays. It also shows how to derive feature-specific RNGs for procedural generation and provides examples for deterministic terrain generation, loot drops, and networked gameplay consistency. ```csharp using FixedMathSharp.Utility; using FixedMathSharp; // Create RNG with seed var rng = new DeterministicRandom(42UL); // Generate integers int randomInt = rng.Next(); // [0, int.MaxValue] int bounded = rng.Next(10); // [0, 10) int range = rng.Next(5, 15); // [5, 15) // Generate doubles double randomDouble = rng.NextDouble(); // [0, 1) // Generate Fixed64 values Fixed64 fixed01 = rng.NextFixed6401(); // [0, 1) Fixed64 fixedMax = rng.NextFixed64(new Fixed64(100)); // [0, 100) Fixed64 fixedRange = rng.NextFixed64( new Fixed64(-10), new Fixed64(10) ); // [-10, 10) // Generate bytes Span buffer = stackalloc byte[16]; rng.NextBytes(buffer); // World feature streams (for procedural generation) ulong worldSeed = 123456789UL; var oreRng = DeterministicRandom.FromWorldFeature(worldSeed, 0xORE); var riverRng = DeterministicRandom.FromWorldFeature(worldSeed, 0xRIV); var treeRng = DeterministicRandom.FromWorldFeature(worldSeed, 0xTREE); // Each feature generates independently but deterministically Fixed64 oreSpawnChance = oreRng.NextFixed6401(); Fixed64 riverWidth = riverRng.NextFixed64(new Fixed64(5), new Fixed64(20)); int treeCount = treeRng.Next(10, 50); // Practical example: deterministic procedural generation ulong mapSeed = 987654321UL; var terrainRng = DeterministicRandom.FromWorldFeature(mapSeed, 0x5445); // "TE" for (int x = 0; x < 100; x++) { for (int z = 0; z < 100; z++) { // Create chunk-specific RNG var chunkRng = DeterministicRandom.FromWorldFeature( mapSeed, 0x4348, // "CH" (ulong)(x * 1000 + z) ); // Generate deterministic terrain height Fixed64 height = chunkRng.NextFixed64(new Fixed64(0), new Fixed64(50)); // Generate structures Fixed64 treeSpawnChance = chunkRng.NextFixed6401(); if (treeSpawnChance > new Fixed64(0.95)) { // Spawn tree at (x, height, z) Fixed64 treeHeight = chunkRng.NextFixed64(new Fixed64(5), new Fixed64(15)); } // Generate resources Fixed64 resourceRoll = chunkRng.NextFixed6401(); if (resourceRoll < new Fixed64(0.1)) { // Spawn ore deposit int oreAmount = chunkRng.Next(5, 20); } } } // Practical example: deterministic loot drops var lootRng = new DeterministicRandom(555UL); Fixed64 dropChance = lootRng.NextFixed6401(); string lootItem; if (dropChance < new Fixed64(0.01)) { lootItem = "Legendary"; } else if (dropChance < new Fixed64(0.1)) { lootItem = "Rare"; } else if (dropChance < new Fixed64(0.4)) { lootItem = "Uncommon"; } else { lootItem = "Common"; } // Practical example: networked multiplayer consistency // All clients use same seed to generate identical results ulong gameSeed = 111222333UL; var gameRng = new DeterministicRandom(gameSeed); // Critical hits are deterministic for (int attackNumber = 0; attackNumber < 100; attackNumber++) { Fixed64 critRoll = gameRng.NextFixed6401(); bool isCritical = critRoll < new Fixed64(0.15); // 15% crit chance // All clients compute identical critical hits } ``` -------------------------------- ### FixedMathSharp Vector3d Operations in C# Source: https://context7.com/mrdav30/fixedmathsharp/llms.txt Illustrates the usage of `Vector3d` for 3D spatial calculations with fixed-point components, ensuring deterministic results. This includes vector construction, basic arithmetic, magnitude, dot and cross products, distance calculations, interpolation (Lerp/Slerp), in-place modifications, projections, and angle calculations. Practical examples for movement and collision are also provided. ```csharp using FixedMathSharp; // Vector construction Vector3d position = new Vector3d(10, 20, 30); Vector3d velocity = new Vector3d(1.5, 2.0, -0.5); Vector3d up = Vector3d.Up; // (0, 1, 0) Vector3d forward = Vector3d.Forward; // (0, 0, 1) // Basic operations Vector3d sum = position + velocity; Vector3d scaled = velocity * new Fixed64(2.5); Vector3d normalized = velocity.Normal; // Unit vector Fixed64 magnitude = velocity.Magnitude; // Length of vector // Dot product and cross product Fixed64 dot = Vector3d.Dot(velocity, forward); Vector3d cross = Vector3d.Cross(velocity, forward); // Distance calculations (prefer SqrDistance for performance) Fixed64 distance = Vector3d.Distance(position, Vector3d.Zero); Fixed64 sqrDist = Vector3d.SqrDistance(position, Vector3d.Zero); // Faster // Interpolation for smooth movement Vector3d start = new Vector3d(0, 0, 0); Vector3d end = new Vector3d(100, 50, 25); Fixed64 t = new Fixed64(0.5); // 50% interpolation Vector3d lerped = Vector3d.Lerp(start, end, t); // Result: (50, 25, 12.5) Vector3d slerped = Vector3d.Slerp(start.Normal, end.Normal, t); // Spherical // In-place modifications for performance position.AddInPlace(velocity); // position += velocity position.ScaleInPlace(new Fixed64(2)); // position *= 2 position.Normalize(); // Make unit length // Projection and angles Vector3d projected = Vector3d.Project(velocity, up); Vector3d onPlane = Vector3d.ProjectOnPlane(velocity, up); Fixed64 angle = Vector3d.Angle(velocity, forward); // Angle in degrees // Practical example: movement with collision Vector3d playerPos = new Vector3d(5, 0, 5); Vector3d moveDir = new Vector3d(1, 0, 1).Normal; Fixed64 speed = new Fixed64(2.5); Fixed64 deltaTime = new Fixed64(0.016); // ~60 FPS Vector3d newPos = playerPos + (moveDir * speed * deltaTime); ``` -------------------------------- ### C# AABB Collision Detection and Frustum Culling Examples Source: https://context7.com/mrdav30/fixedmathsharp/llms.txt Provides practical examples of using BoundingBox for Axis-Aligned Bounding Box (AABB) collision detection in game development scenarios and for frustum culling to optimize rendering. Fixed-point math ensures precision in these operations. ```csharp using FixedMathSharp; // Practical example: AABB collision detection BoundingBox player = new BoundingBox(new Vector3d(0, 1, 0), new Vector3d(1, 2, 1)); BoundingBox wall = new BoundingBox(new Vector3d(10, 1, 0), new Vector3d(2, 10, 20)); BoundingBox obstacle = new BoundingBox(new Vector3d(5, 0.5f, 0), new Vector3d(3, 1, 3)); Vector3d moveDir = new Vector3d(1, 0, 0).Normal; Fixed64 moveSpeed = new Fixed64(5); Fixed64 dt = new Fixed64(0.016); Vector3d newPlayerPos = player.Center + moveDir * moveSpeed * dt; BoundingBox newPlayerBox = new BoundingBox(newPlayerPos, player.Size); bool wouldCollideWall = newPlayerBox.Intersects(wall); bool wouldCollideObstacle = newPlayerBox.Intersects(obstacle); if (!wouldCollideWall && !wouldCollideObstacle) { player = newPlayerBox; // Safe to move } // Practical example: frustum culling BoundingBox[] objects = new BoundingBox[100]; BoundingBox frustumBox = new BoundingBox(Vector3d.Zero, new Vector3d(50, 50, 100)); foreach (var obj in objects) { if (frustumBox.Intersects(obj)) { // Object is visible, render it } } ``` -------------------------------- ### FixedMathSharp Trigonometry and Math Operations in C# Source: https://context7.com/mrdav30/fixedmathsharp/llms.txt This C# code snippet demonstrates various mathematical and trigonometric functions provided by the FixedMathSharp library. It utilizes fixed-point precision for deterministic results. The snippet covers constants, trigonometric functions, inverse trigonometric functions, angle conversions, power, square root, min/max/clamp operations, and includes examples for circular motion and projectile trajectory. ```csharp using FixedMathSharp; // Constants Fixed64 pi = FixedMath.PI; // 3.14159... Fixed64 piOver2 = FixedMath.PiOver2; // π/2 Fixed64 piOver4 = FixedMath.PiOver4; // π/4 Fixed64 twoPi = FixedMath.TwoPI; // 2π // Trigonometric functions (input in radians) Fixed64 angle = FixedMath.PiOver4; // 45 degrees Fixed64 sinValue = FixedMath.Sin(angle); // Result: ~0.707 Fixed64 cosValue = FixedMath.Cos(angle); // Result: ~0.707 Fixed64 tanValue = FixedMath.Tan(angle); // Result: ~1.0 // Inverse trigonometric functions Fixed64 asinResult = FixedMath.Asin(new Fixed64(0.5)); // Result: ~0.524 (30°) Fixed64 acosResult = FixedMath.Acos(new Fixed64(0.5)); // Result: ~1.047 (60°) Fixed64 atanResult = FixedMath.Atan(new Fixed64(1)); // Result: ~0.785 (45°) Fixed64 atan2Result = FixedMath.Atan2(new Fixed64(1), new Fixed64(1)); // Result: ~0.785 // Angle conversion Fixed64 degrees = new Fixed64(180); Fixed64 radians = FixedMath.DegToRad(degrees); // Result: π Fixed64 backToDeg = FixedMath.RadToDeg(radians); // Result: 180 // Power and square root Fixed64 squared = FixedMath.Pow(new Fixed64(3), 2); // Result: 9 Fixed64 cubed = FixedMath.Pow(new Fixed64(2), 3); // Result: 8 Fixed64 sqrt = FixedMath.Sqrt(new Fixed64(16)); // Result: 4 // Min, max, clamp Fixed64 min = FixedMath.Min(new Fixed64(5), new Fixed64(10)); Fixed64 max = FixedMath.Max(new Fixed64(5), new Fixed64(10)); Fixed64 clamped = FixedMath.Clamp(new Fixed64(150), new Fixed64(0), new Fixed64(100)); Fixed64 clamp01 = FixedMath.Clamp01(new Fixed64(1.5)); // Result: 1.0 // Practical example: circular motion Fixed64 radius = new Fixed64(10); Fixed64 time = new Fixed64(0); Fixed64 angularSpeed = new Fixed64(2); // 2 radians per second for (int i = 0; i < 60; i++) { Fixed64 currentAngle = angularSpeed * time; Fixed64 x = radius * FixedMath.Cos(currentAngle); Fixed64 y = radius * FixedMath.Sin(currentAngle); Vector3d position = new Vector3d(x, y, Fixed64.Zero); time += new Fixed64(0.016); // 60 FPS } // Practical example: projectile trajectory Vector3d launchPos = new Vector3d(0, 0, 0); Fixed64 launchAngle = FixedMath.DegToRad(new Fixed64(45)); Fixed64 launchSpeed = new Fixed64(20); Fixed64 gravity = new Fixed64(-9.8); Fixed64 timeStep = new Fixed64(0.016); Fixed64 vx = launchSpeed * FixedMath.Cos(launchAngle); Fixed64 vy = launchSpeed * FixedMath.Sin(launchAngle); Vector3d velocity = new Vector3d(vx, vy, Fixed64.Zero); Vector3d currentPos = launchPos; for (Fixed64 t = Fixed64.Zero; t < new Fixed64(3); t += timeStep) { currentPos = launchPos + velocity * t + new Vector3d(Fixed64.Zero, gravity * t * t * Fixed64.Half, Fixed64.Zero); } ``` -------------------------------- ### Run Unit Tests Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md This command executes the unit tests for the FixedMathSharp project in debug configuration. It's essential for validating the correctness of the mathematical operations implemented within the library. ```bash dotnet test --configuration debug ``` -------------------------------- ### Cloning the FixedMathSharp Repository in Bash Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md Shows the Git command to clone the FixedMathSharp repository from GitHub. This method is useful for developers who want to access the source code directly or contribute to the project. ```bash git clone https://github.com/mrdav30/FixedMathSharp.git ``` -------------------------------- ### FixedMathSharp: 3x3 Rotation Matrix Operations Source: https://context7.com/mrdav30/fixedmathsharp/llms.txt Illustrates the creation and use of 3x3 matrices for rotation within FixedMathSharp. Shows how to convert a quaternion to a 3x3 rotation matrix and then use it to rotate a vector. ```csharp using FixedMathSharp; // 3x3 rotation matrix Fixed3x3 rotMatrix = new Fixed3x3(); FixedQuaternion quat = FixedQuaternion.FromAxisAngle(Vector3d.Up, FixedMath.PiOver2); Fixed3x3 fromQuat = quat.ToMatrix3x3(); Vector3d rotatedVec = fromQuat * new Vector3d(1, 0, 0); ``` -------------------------------- ### Matrix Transformations in C# Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md Demonstrates setting a transformation (position, scale, rotation) on a `Fixed4x4` matrix. This is fundamental for applying transformations in 3D graphics and physics engines. ```csharp Fixed4x4 matrix = Fixed4x4.Identity; Vector3d position = new Vector3d(1, 2, 3); matrix.SetTransform(position, Vector3d.One, FixedQuaternion.Identity); Console.WriteLine(matrix); ``` -------------------------------- ### C# Bounding Box Creation and Intersection Tests Source: https://context7.com/mrdav30/fixedmathsharp/llms.txt Demonstrates how to create BoundingBox, BoundingSphere instances, and perform intersection tests between them. It also shows how to check if a box contains a point, sphere, or another box, and how to test for ray intersection. The FixedMathSharp library is used for fixed-point precision. ```csharp using FixedMathSharp; // Create bounding boxes Vector3d center = new Vector3d(0, 0, 0); Vector3d size = new Vector3d(10, 10, 10); BoundingBox box = new BoundingBox(center, size); Vector3d minCorner = new Vector3d(-5, -5, -5); Vector3d maxCorner = new Vector3d(5, 5, 5); BoundingBox boxFromCorners = BoundingBox.CreateFromMinMax(minCorner, maxCorner); // Bounding sphere Vector3d sphereCenter = new Vector3d(5, 5, 5); Fixed64 radius = new Fixed64(3); BoundingSphere sphere = new BoundingSphere(sphereCenter, radius); // Intersection tests bool boxIntersectsSphere = box.Intersects(sphere); BoundingBox otherBox = new BoundingBox(new Vector3d(8, 0, 0), new Vector3d(5, 5, 5)); bool boxesIntersect = box.Intersects(otherBox); // Containment tests Vector3d point = new Vector3d(2, 2, 2); bool containsPoint = box.Contains(point); bool containsSphere = box.Contains(sphere); bool containsBox = box.Contains(otherBox); // Ray intersection Vector3d rayOrigin = new Vector3d(-20, 0, 0); Vector3d rayDirection = new Vector3d(1, 0, 0).Normal; Fixed64 maxDistance = new Fixed64(100); bool rayHits = box.Intersects(rayOrigin, rayDirection, out Fixed64 distance); if (rayHits) { Vector3d hitPoint = rayOrigin + rayDirection * distance; } // Closest point on bounding box Vector3d externalPoint = new Vector3d(20, 20, 20); Vector3d closestPoint = box.ClosestPoint(externalPoint); // Expand/merge bounding boxes BoundingBox expanded = box.Expand(new Fixed64(2)); // Expand by 2 units BoundingBox merged = BoundingBox.Merge(box, otherBox); ``` -------------------------------- ### FixedMathSharp: 4x4 Matrix Transformations Source: https://context7.com/mrdav30/fixedmathsharp/llms.txt Demonstrates the creation and manipulation of 4x4 matrices for transformations. Includes setting position, scale, rotation, transforming vectors, matrix operations like multiplication and transpose, and extracting transformation components. It also covers creating a view matrix for a camera. ```csharp using FixedMathSharp; // Create matrices Fixed4x4 identity = Fixed4x4.Identity; Fixed4x4 transform = new Fixed4x4(); // Set transformation (position, scale, rotation) Vector3d position = new Vector3d(10, 5, 3); Vector3d scale = Vector3d.One * new Fixed64(2); // Uniform scale 2x FixedQuaternion rotation = FixedQuaternion.FromEulerAnglesInDegrees( new Fixed64(0), new Fixed64(90), new Fixed64(0) ); transform.SetTransform(position, scale, rotation); // Transform vectors and points Vector3d localPoint = new Vector3d(1, 0, 0); Vector3d worldPoint = transform * localPoint; // Matrix operations Fixed4x4 matrixA = Fixed4x4.Identity; Fixed4x4 matrixB = Fixed4x4.Identity; Fixed4x4 multiplied = matrixA * matrixB; Fixed4x4 transposed = matrixA.Transpose(); // Extract components Vector3d extractedPos = transform.GetPosition(); Vector3d extractedScale = transform.GetScale(); FixedQuaternion extractedRot = FixedQuaternion.FromMatrix(transform); // Practical example: hierarchical transforms (parent-child) Fixed4x4 parentTransform = Fixed4x4.Identity; parentTransform.SetTransform( new Vector3d(10, 0, 0), // Parent position Vector3d.One, // Parent scale FixedQuaternion.Identity // Parent rotation ); Fixed4x4 childLocalTransform = Fixed4x4.Identity; childLocalTransform.SetTransform( new Vector3d(5, 0, 0), // Child local position Vector3d.One, FixedQuaternion.Identity ); Fixed4x4 childWorldTransform = parentTransform * childLocalTransform; Vector3d childWorldPos = childWorldTransform.GetPosition(); // (15, 0, 0) // Practical example: view matrix for camera Vector3d cameraPos = new Vector3d(0, 10, -10); Vector3d lookAtTarget = Vector3d.Zero; Vector3d cameraUp = Vector3d.Up; Vector3d forward = (lookAtTarget - cameraPos).Normal; FixedQuaternion cameraRot = FixedQuaternion.LookRotation(forward, cameraUp); Fixed4x4 viewMatrix = Fixed4x4.Identity; viewMatrix.SetTransform(cameraPos, Vector3d.One, cameraRot); ``` -------------------------------- ### Basic Arithmetic with Fixed64 in C# Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md Demonstrates fundamental addition operations using the `Fixed64` type for high-precision arithmetic. This is useful for calculations where floating-point inaccuracies need to be avoided. ```csharp Fixed64 a = new Fixed64(1.5); Fixed64 b = new Fixed64(2.5); Fixed64 result = a + b; Console.WriteLine(result); // Output: 4.0 ``` -------------------------------- ### Deterministic Random Generation in C# Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md Demonstrates the use of `DeterministicRandom` for generating reproducible random numbers, crucial for simulations and ensuring consistency across different runs or platforms. It supports simple streams and feature-specific streams derived from seeds. ```csharp // Simple constructor-based stream: var rng = new DeterministicRandom(42UL); // Deterministic integer: int value = rng.Next(1, 10); // [1,10) // Deterministic Fixed64 in [0,1): Fixed64 ratio = rng.NextFixed6401(); // One stream per “feature” that’s stable for the same worldSeed + key: var rngOre = DeterministicRandom.FromWorldFeature(worldSeed: 123456789UL, featureKey: 0xORE); var rngRivers = DeterministicRandom.FromWorldFeature(123456789UL, 0xRIV, index: 0); // Deterministic Fixed64 draws: Fixed64 h = rngOre.NextFixed64(Fixed64.One); // [0, 1) Fixed64 size = rngOre.NextFixed64(Fixed64.Zero, 5 * Fixed64.One); // [0, 5) Fixed64 posX = rngRivers.NextFixed64(-Fixed64.One, Fixed64.One); // [-1, 1) // Deterministic integers: int loot = rngOre.Next(1, 5); // [1,5) ``` -------------------------------- ### FixedQuaternion Rotations using C# in fixedmathsharp Source: https://context7.com/mrdav30/fixedmathsharp/llms.txt Demonstrates various operations with FixedQuaternion in C#, including creation, vector rotation, combination, interpolation, and conversion. This library avoids gimbal lock and ensures deterministic calculations for 3D rotations. ```csharp using FixedMathSharp; // Create quaternions FixedQuaternion identity = FixedQuaternion.Identity; FixedQuaternion rotation90Y = FixedQuaternion.FromAxisAngle( Vector3d.Up, FixedMath.PiOver2 // 90 degrees in radians ); // From Euler angles (pitch, yaw, roll in degrees) FixedQuaternion eulerRot = FixedQuaternion.FromEulerAnglesInDegrees( new Fixed64(45), // pitch new Fixed64(90), // yaw new Fixed64(0) // roll ); // Rotate vectors Vector3d point = new Vector3d(1, 0, 0); Vector3d rotated = rotation90Y * point; // Result: ~(0, 0, -1) // Quaternion multiplication (combine rotations) FixedQuaternion rotX = FixedQuaternion.FromAxisAngle(Vector3d.Right, FixedMath.PiOver4); FixedQuaternion rotY = FixedQuaternion.FromAxisAngle(Vector3d.Up, FixedMath.PiOver4); FixedQuaternion combined = rotY * rotX; // Apply rotX then rotY // Interpolation for smooth rotation FixedQuaternion start = FixedQuaternion.Identity; FixedQuaternion end = rotation90Y; Fixed64 t = new Fixed64(0.5); FixedQuaternion lerped = FixedQuaternion.Lerp(start, end, t); FixedQuaternion slerped = FixedQuaternion.Slerp(start, end, t); // Smoother // Convert to/from other representations Vector3d eulerAngles = rotation90Y.EulerAngles; // To Euler (degrees) Vector3d direction = rotation90Y.ToDirection(); // To direction vector Fixed3x3 matrix = rotation90Y.ToMatrix3x3(); // To rotation matrix // Look rotation (point towards target) Vector3d target = new Vector3d(10, 0, 10); Vector3d forward = (target - point).Normal; FixedQuaternion lookRot = FixedQuaternion.LookRotation(forward, Vector3d.Up); // Advanced: angular velocity calculation FixedQuaternion previousRot = FixedQuaternion.Identity; FixedQuaternion currentRot = rotation90Y; Fixed64 deltaTime = new Fixed64(0.016); Vector3d angularVel = FixedQuaternion.ToAngularVelocity( currentRot, previousRot, deltaTime ); // Practical example: character rotation Vector3d characterPos = new Vector3d(0, 0, 0); Vector3d targetPos = new Vector3d(5, 0, 5); Vector3d dirToTarget = (targetPos - characterPos).Normal; FixedQuaternion targetRotation = FixedQuaternion.LookRotation(dirToTarget); FixedQuaternion currentRotation = FixedQuaternion.Identity; FixedQuaternion smoothRot = FixedQuaternion.Slerp( currentRotation, targetRotation, new Fixed64(0.1) // Smooth factor ); ``` -------------------------------- ### Fixed64 Basic Arithmetic Operations in C# Source: https://context7.com/mrdav30/fixedmathsharp/llms.txt Demonstrates the construction and basic arithmetic operations of the `Fixed64` type in FixedMathSharp. This includes addition, subtraction, multiplication, division, and mixed-type operations with integers and floats. It also covers advanced functions like Abs, Round, Clamp, and conversions to standard C# types, along with error handling for division by zero. ```csharp using FixedMathSharp; // Construction from various types Fixed64 a = new Fixed64(1.5); // From double Fixed64 b = new Fixed64(2); // From int Fixed64 c = (Fixed64)3.14159; // Explicit cast // Basic arithmetic with overflow protection Fixed64 sum = a + b; // Result: 3.5 Fixed64 difference = b - a; // Result: 0.5 Fixed64 product = a * b; // Result: 3.0 Fixed64 quotient = b / a; // Result: 1.333... // Integer and float operations Fixed64 mixed1 = a + 5; // Add integer: 6.5 Fixed64 mixed2 = a * 2.0f; // Multiply by float: 3.0 // Advanced operations Fixed64 absolute = FixedMath.Abs(new Fixed64(-5.7)); // Result: 5.7 Fixed64 rounded = FixedMath.Round(new Fixed64(3.7)); // Result: 4.0 Fixed64 clamped = FixedMath.Clamp(new Fixed64(150), new Fixed64(0), new Fixed64(100)); // Result: 100 // Conversion and output double toDouble = (double)a; // Convert to double: 1.5 int toInt = (int)a; // Convert to int: 1 Console.WriteLine(a.ToString()); // Output: "1.5" // Error handling try { Fixed64 divByZero = a / Fixed64.Zero; } catch (DivideByZeroException ex) { Console.WriteLine("Division by zero detected"); } ``` -------------------------------- ### Bounding Shapes Intersection in C# Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md Illustrates how to check for intersection between a `BoundingBox` and a `BoundingSphere` using the library's spatial calculation structs. This is useful for collision detection and spatial queries. ```csharp BoundingBox box = new BoundingBox(new Vector3d(0, 0, 0), new Vector3d(5, 5, 5)); BoundingSphere sphere = new BoundingSphere(new Vector3d(3, 3, 3), new Fixed64(1)); bool intersects = box.Intersects(sphere); Console.WriteLine(intersects); // Output: True ``` -------------------------------- ### Vector Operations (Dot Product) in C# Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md Illustrates how to perform vector operations, specifically calculating the dot product between two 3D vectors using the `Vector3d` type. This is common in physics and game development for calculating angles or projections. ```csharp Vector3d v1 = new Vector3d(1, 2, 3); Vector3d v2 = new Vector3d(4, 5, 6); Fixed64 dotProduct = Vector3d.Dot(v1, v2); Console.WriteLine(dotProduct); // Output: 32 ``` -------------------------------- ### Trigonometry with FixedMathSharp in C# Source: https://github.com/mrdav30/fixedmathsharp/blob/main/README.md Shows how to compute trigonometric functions like sine using `FixedTrigonometry` with `Fixed64` values. This provides precise trigonometric results essential for many mathematical calculations. ```csharp Fixed64 angle = FixedMath.PiOver4; // 45 degrees Fixed64 sinValue = FixedTrigonometry.Sin(angle); Console.WriteLine(sinValue); // Output: ~0.707 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.