# Plane

Class · category: Math

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/core/shape/plane.js#L28

An infinite plane. Internally, it's represented in a parametric equation form:
`ax + by + cz + distance = 0`.

A plane is a [normal](https://api.playcanvas.com/engine/classes/Plane.md#normal) and a [distance](https://api.playcanvas.com/engine/classes/Plane.md#distance) from the origin along that normal. Define one
with the constructor or [setFromPointNormal](https://api.playcanvas.com/engine/classes/Plane.md#setfrompointnormal) from a normal and a point the plane passes
through, or with [set](https://api.playcanvas.com/engine/classes/Plane.md#set) from the four coefficients. None of these normalize the normal they
are given, and [distance](https://api.playcanvas.com/engine/classes/Plane.md#distance) is only a true distance when the normal is unit length, so call
[normalize](https://api.playcanvas.com/engine/classes/Plane.md#normalize) afterwards if it is not. [intersectsRay](https://api.playcanvas.com/engine/classes/Plane.md#intersectsray) and [intersectsLine](https://api.playcanvas.com/engine/classes/Plane.md#intersectsline)
return whether a hit occurred and write the hit point into an optional vector. The ray's
direction must be normalized.

**Example**

```ts
// Find where a ray from the camera meets the ground plane at y = 0
const ground = new Plane(Vec3.UP, 0);
const hit = new Vec3();
if (ground.intersectsRay(ray, hit)) {
    marker.setPosition(hit);
}
```

## Constructors

### constructor

```ts
new Plane(normal?: Vec3, distance?: number)
```

Create a new Plane instance.

**Parameters**

- `normal` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md), optional, default `Vec3.UP`): Normal of the plane. The constructor copies this parameter. Defaults
  to [Vec3.UP](https://api.playcanvas.com/engine/classes/Vec3.md#up).
- `distance` (`number`, optional, default `0`): The distance from the plane to the origin, along its normal.
  Defaults to 0.

## Properties

### distance

```ts
distance: number
```

The distance from the plane to the origin, along its normal.

### normal

```ts
normal: Vec3
```

The normal of the plane.

## Methods

### clone

```ts
clone(): Plane
```

Returns a clone of the specified plane.

**Returns** [`Plane`](https://api.playcanvas.com/engine/classes/Plane.md): A duplicate plane.

### copy

```ts
copy(src: Plane): Plane
```

Copies the contents of a source plane to a destination plane.

**Parameters**

- `src` ([`Plane`](https://api.playcanvas.com/engine/classes/Plane.md)): A source plane to copy to the destination plane.

**Returns** [`Plane`](https://api.playcanvas.com/engine/classes/Plane.md): Self for chaining.

### intersectsLine

```ts
intersectsLine(start: Vec3, end: Vec3, point?: Vec3): boolean
```

Test if the plane intersects between two points.

**Parameters**

- `start` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md)): Start position of line.
- `end` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md)): End position of line.
- `point` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md), optional): If there is an intersection, the intersection point will be copied
  into here.

**Returns** `boolean`: True if there is an intersection.

### intersectsRay

```ts
intersectsRay(ray: Ray, point?: Vec3): boolean
```

Test if a ray intersects with the infinite plane.

**Parameters**

- `ray` ([`Ray`](https://api.playcanvas.com/engine/classes/Ray.md)): Ray to test against (direction must be normalized).
- `point` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md), optional): If there is an intersection, the intersection point will be copied
  into here.

**Returns** `boolean`: True if there is an intersection.

### normalize

```ts
normalize(): Plane
```

Normalize the plane.

**Returns** [`Plane`](https://api.playcanvas.com/engine/classes/Plane.md): Self for chaining.

### set

```ts
set(nx: number, ny: number, nz: number, d: number): Plane
```

Sets the plane based on a normal and a distance from the origin.

**Parameters**

- `nx` (`number`): The x-component of the normal.
- `ny` (`number`): The y-component of the normal.
- `nz` (`number`): The z-component of the normal.
- `d` (`number`): The distance from the origin.

**Returns** [`Plane`](https://api.playcanvas.com/engine/classes/Plane.md): Self for chaining.

### setFromPointNormal

```ts
setFromPointNormal(point: Vec3, normal: Vec3): Plane
```

Sets the plane based on a specified normal and a point on the plane.

**Parameters**

- `point` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md)): The point on the plane.
- `normal` ([`Vec3`](https://api.playcanvas.com/engine/classes/Vec3.md)): The normal of the plane.

**Returns** [`Plane`](https://api.playcanvas.com/engine/classes/Plane.md): Self for chaining.
