# TryGetRelativeMatrix2D

> Try to get the relative transformation matrix between the two specified transform matrix using the specified transform plane to transform into 2D space, the same as PhysicsMath.GetRelativeMatrix2D but never returning a NaN result. Each matrix is checked first: if its scale on the plane's ignored axis is at or near zero, such as a matrix built from flattened 2D data, that axis is treated as one instead of leaving the matrix singular. Returns false, instead of a matrix with a NaN rotation, when either matrix has too small an in-plane scale to work with, or the relative transform itself is too close to singular to invert cleanly.

## Definition

* **Type:** Method
* **Namespace:** [Unity.U2D.Physics](/engine/6000.7/script-reference/unity/u2d/physics.md)
* **Assembly:** UnityEngine.PhysicsCore2DModule

## TryGetRelativeMatrix2D(Matrix4x4, Matrix4x4, TransformPlane, TransformPlaneCustom, Matrix4x4)

Try to get the relative transformation matrix between the two specified transform matrix using the specified transform plane to transform into 2D space, the same as [PhysicsMath.GetRelativeMatrix2D](/engine/6000.7/script-reference/unity/u2d/physics/physicsmath/getrelativematrix2d.md) but never returning a NaN result. Each matrix is checked first: if its scale on the plane's ignored axis is at or near zero, such as a matrix built from flattened 2D data, that axis is treated as one instead of leaving the matrix singular. Returns false, instead of a matrix with a NaN rotation, when either matrix has too small an in-plane scale to work with, or the relative transform itself is too close to singular to invert cleanly.

```csharp
public static bool TryGetRelativeMatrix2D(in Matrix4x4 transformFrom, in Matrix4x4 transformTo, PhysicsWorld.TransformPlane transformPlane, in PhysicsWorld.TransformPlaneCustom transformPlaneCustom, out Matrix4x4 relative)
```

### Parameters

**** (\[Matrix4x4]\(/engine/6000.7/script-reference/unityengine/matrix4x4)): The transform used as a reference to transform from.**** (\[Matrix4x4]\(/engine/6000.7/script-reference/unityengine/matrix4x4)): The transform used as a reference to transform to.**** (\[TransformPlane]\(/engine/6000.7/script-reference/unity/u2d/physics/physicsworld/transformplane)): The transform plane to use.**** (\[TransformPlaneCustom]\(/engine/6000.7/script-reference/unity/u2d/physics/physicsworld/transformplanecustom)): The custom transform plane to use (if required).**** (\[Matrix4x4]\(/engine/6000.7/script-reference/unityengine/matrix4x4)): The calculated relative transformation matrix, or the identity matrix if this returns false.

### Returns

| Type                                                          | Description                                                    |
| ------------------------------------------------------------- | -------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Whether a valid relative transformation matrix was calculated. |

## TryGetRelativeMatrix2D(Matrix4x4, Matrix4x4, PhysicsWorld, Matrix4x4)

Try to get the relative transformation matrix between the two specified transform matrix using the specified world's transform plane, never returning a NaN result.

```csharp
public static bool TryGetRelativeMatrix2D(in Matrix4x4 transformFrom, in Matrix4x4 transformTo, PhysicsWorld world, out Matrix4x4 relative)
```

### Parameters

**** (\[Matrix4x4]\(/engine/6000.7/script-reference/unityengine/matrix4x4)): The transform used as a reference to transform from.**** (\[Matrix4x4]\(/engine/6000.7/script-reference/unityengine/matrix4x4)): The transform used as a reference to transform to.**** (\[PhysicsWorld]\(/engine/6000.7/script-reference/unity/u2d/physics/physicsworld)): The world whose transform plane is used.**** (\[Matrix4x4]\(/engine/6000.7/script-reference/unityengine/matrix4x4)): The calculated relative transformation matrix, or the identity matrix if this returns false.

### Returns

| Type                                                          | Description                                                    |
| ------------------------------------------------------------- | -------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Whether a valid relative transformation matrix was calculated. |
