#

API Docs for: 0.6.0
Show: Inherited Protected Private Deprecated

# Heightfield Class

Extends Shape
Defined in: `src/shapes/Heightfield.js:8`

Heightfield shape class. Height data is given as an array. These data points are spread out evenly with a given distance.

## Constructor

### `Heightfield`

(

- `data`
- `options`

)

Defined in `src/shapes/Heightfield.js:8`

#### Parameters:

- `data` Array

  An array of Y values that will be used to construct the terrain.

- `options` Object
  - `[minValue]` Number optional

    Minimum value of the data points in the data array. Will be computed automatically if not given.

  - `[maxValue]` Number optional

    Maximum value.

  - `[elementSize=0.1]` Number optional

    World spacing between the data points in X direction.

#### Example:

    // Generate some height data (y-values).
    var data = [];
    for(var i = 0; i < 1000; i++){
        var y = 0.5 * Math.cos(0.2 * i);
        data.push(y);
    }

    // Create the heightfield shape
    var heightfieldShape = new Heightfield(data, {
        elementSize: 1 // Distance between the data points in X and Y directions
    });
    var heightfieldBody = new Body();
    heightfieldBody.addShape(heightfieldShape);
    world.addBody(heightfieldBody);

- Index
- Methods
- Properties

## Item Index

### Methods

- calculateLocalInertia
- getConvexTrianglePillar
- getIndexOfPosition
- getRectMinMax
- setHeightValueAtIndex
- update
- updateBoundingSphereRadius
- updateMaxValue
- updateMinValue Update the .minValue property
- volume

### Properties

- boundingSphereRadius
- collisionResponse
- data
- elementSize
- maxValue
- minValue
- type

## Methods

### `calculateLocalInertia`

() Vec3

Inherited from Shape: `src/shapes/Shape.js:56`

Calculates the inertia in the local frame for this shape.

#### Returns:

Vec3:

### `getConvexTrianglePillar`

(

- `i`
- `j`
- `getUpperTriangle`

)

Defined in `src/shapes/Heightfield.js:257`

Get a triangle in the terrain in the form of a triangular convex shape.

#### Parameters:

- `i` Integer
- `j` Integer
- `getUpperTriangle` Boolean

### `getIndexOfPosition`

(

- `x`
- `y`
- `result`
- `clamp`

)
Boolean

Defined in `src/shapes/Heightfield.js:191`

Get the index of a local position on the heightfield. The indexes indicate the rectangles, so if your terrain is made of N x N height data points, you will have rectangle indexes ranging from 0 to N-1.

#### Parameters:

- `x` Number
- `y` Number
- `result` Array

  Two-element array

- `clamp` Boolean

  If the position should be clamped to the heightfield edge.

#### Returns:

Boolean:

### `getRectMinMax`

(

- `iMinX`
- `iMinY`
- `iMaxX`
- `iMaxY`
- `[result]`

)
Array

Defined in `src/shapes/Heightfield.js:162`

Get max/min in a rectangle in the matrix data

#### Parameters:

- `iMinX` Integer
- `iMinY` Integer
- `iMaxX` Integer
- `iMaxY` Integer
- `[result]` Array optional

  An array to store the results in.

#### Returns:

Array:

The result array, if it was passed in. Minimum will be at position 0 and max at 1.

### `setHeightValueAtIndex`

(

- `xi`
- `yi`
- `value`

)

Defined in `src/shapes/Heightfield.js:136`

Set the height value at an index. Don't forget to update maxValue and minValue after you're done.

#### Parameters:

- `xi` Integer
- `yi` Integer
- `value` Number

### `update`

()

Defined in `src/shapes/Heightfield.js:92`

Call whenever you change the data array.

### `updateBoundingSphereRadius`

() Number

Inherited from Shape: `src/shapes/Shape.js:38`

Computes the bounding sphere radius. The result is stored in the property .boundingSphereRadius

#### Returns:

Number:

### `updateMaxValue`

()

Defined in `src/shapes/Heightfield.js:118`

Update the .maxValue property

### `updateMinValue Update the .minValue property`

()

Defined in `src/shapes/Heightfield.js:100`

### `volume`

() Number

Inherited from Shape: `src/shapes/Shape.js:47`

Get the volume of this shape

#### Returns:

Number:

## Properties

### `boundingSphereRadius`

Number

Inherited from Shape: `src/shapes/Shape.js:25`

The local bounding sphere radius of this shape.

### `collisionResponse`

Boolean

Inherited from Shape: `src/shapes/Shape.js:31`

### `data`

Array

Defined in `src/shapes/Heightfield.js:43`

An array of numbers, or height values, that are spread out along the x axis.

### `elementSize`

Number

Defined in `src/shapes/Heightfield.js:61`

The width of each element

### `maxValue`

Number

Defined in `src/shapes/Heightfield.js:49`

Max value of the data

### `minValue`

Number

Defined in `src/shapes/Heightfield.js:55`

Max value of the data

### `type`

Number

Inherited from Shape: `src/shapes/Shape.js:17`

The type of this shape. Must be set to an int > 0 by subclasses.