---
title: "Find affine volume scale in C#"
url: https://recursiveai.org/onemath/cookbook/calculate-affine-volume-scale/
description: "Use the absolute determinant of a 3×3 matrix to find an affine transform’s volume multiplier in C#. Read the sign separately to detect orientation reversal."
version: "1.0.0"
---

# Find affine volume scale in C#

**OneMath** is a free, open-source deterministic math library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneMath) · [GitHub](https://github.com/recursive-ai-oss/onemath-csharp) · [Docs](https://recursiveai.org/onemath/docs/) · [Download example (.zip)](https://recursiveai.org/onemath/cookbook/calculate-affine-volume-scale/calculate-affine-volume-scale.zip)

The determinant’s absolute value is the volume scaling factor; a negative sign means orientation flips.

```shell
dotnet add package RecursiveAI.OneMath
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneMath;
var det = new Matrix3x3D(-2, 0, 0,
    0, 3, 0, 0, 0, 4).Determinant();
Console.WriteLine(Math.Abs(det));
Console.WriteLine(det < 0);
```

Unzip [the example](https://recursiveai.org/onemath/cookbook/calculate-affine-volume-scale/calculate-affine-volume-scale.zip), then `dotnet run`.

```text
24
True
```

Volume scales by 24; `True` means orientation reverses.

## The full program

```csharp
using RecursiveAI.OneMath;

var transform = new Affine3D(
    new Matrix3x3D(-2, 0, 0, 0, 3, 0, 0, 0, 4),
    new Vector3D(10, 20, 30));
double determinant = transform.Linear.Determinant();
Console.WriteLine($"Determinant: {determinant}");
Console.WriteLine($"Volume multiplier: {Math.Abs(determinant)}");
Console.WriteLine($"Reverses orientation: {determinant < 0}");
Console.WriteLine($"Volume after (from 2): {2 * Math.Abs(determinant)}");
```

`dotnet run` prints:

```text
Determinant: -24
Volume multiplier: 24
Reverses orientation: True
Volume after (from 2): 48
```

If the floating-point determinant is nonfinite, don’t use it as a volume multiplier.

## Variations

`Matrix3x3D` takes its nine arguments in row-major order: the first row, then the second, then the third. Here, the `2` in the first row adds twice Y to X without changing the volume:

```csharp
using RecursiveAI.OneMath;

var shear = new Matrix3x3D(1, 2, 0, 0, 1, 0, 0, 0, 1);
Console.WriteLine(Math.Abs(shear.Determinant()));
```

```text
1
```

## Related recipes

- [Compose affine scale and shear](https://recursiveai.org/onemath/cookbook/compose-affine-scale-and-shear/)
- [Invert a matrix](https://recursiveai.org/onemath/cookbook/invert-matrix/)

## The short answer

Call `transform.Linear.Determinant()` for an `Affine3D` and take `Math.Abs` of the result to get the volume multiplier. If you already have the `Matrix3x3D`, call `Determinant()` directly on it. Multiply the original volume by that nonnegative factor. Keep the signed determinant separately to tell whether the transform reverses orientation.

## Why is the determinant the volume scaling factor?

For a linear transform, the three transformed unit axes are the columns of the matrix. Together they span a parallelepiped, the transformed unit cube. Its volume is the magnitude of the determinant. That same factor applies to the volume of other shapes under the same linear map; see Georgia Tech’s [Determinants and Volumes](https://textbooks.math.gatech.edu/ila/determinants-volumes.html).

An affine transform adds a translation after the linear map, as shown in [OneMath’s `Affine3D` source](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/src/OneMath/Types/Affine3D.cs#L10-L29). Translation shifts every point by the same amount, so the edges of the transformed cube and its volume don’t depend on that offset. This is why the full program uses only `transform.Linear` even with a translation of `(10, 20, 30)`. A shear can change the edges without changing volume: in the variation, the sheared cube has slanted sides but the same base area and height.

## What does a negative determinant mean for volume?

The sign tells you about orientation, not the amount of space occupied. The example scales X by −2, Y by 3, and Z by 4. Reflecting along X reverses orientation; the three length multipliers are still 2, 3, and 4. That gives a signed determinant of −24 and a volume multiplier of 24. A shape with volume 2 therefore has volume 48 after the transform.

A mathematically zero determinant means the linear map collapses three-dimensional volume, such as a scale that sets Z to zero. Don’t treat the computed value as an exact test for that condition: [OneMath’s implementation](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/src/OneMath/Types/Matrix3x3D.cs#L142-L149) uses a cofactor expansion in `double`. The products can overflow or underflow, and subtraction can lose precision when terms are nearly equal. Even the sign can be sensitive near a collapse. Use the multiplier here to measure ordinary transforms, not as an exact degeneracy predicate.
