# Cartesian4

A 4D Cartesian point.

#### new Cesium.Cartesian4(x, y, z, w)
engine/Source/Core/Cartesian4.js 18

Name | Type | Default | Description
--- | --- | --- | ---
`x` | number | `0.0` | optional The X component.
`y` | number | `0.0` | optional The Y component.
`z` | number | `0.0` | optional The Z component.
`w` | number | `0.0` | optional The W component.

##### See:

- Cartesian2
- Cartesian3
- Packable

### Members

#### w : number
engine/Source/Core/Cartesian4.js 52

The W component.

Default Value: `0.0`

#### x : number
engine/Source/Core/Cartesian4.js 31

The X component.

Default Value: `0.0`

#### y : number
engine/Source/Core/Cartesian4.js 38

The Y component.

Default Value: `0.0`

#### z : number
engine/Source/Core/Cartesian4.js 45

The Z component.

Default Value: `0.0`

#### static constant Cesium.Cartesian4.ONE : Cartesian4
engine/Source/Core/Cartesian4.js 940

An immutable Cartesian4 instance initialized to (1.0, 1.0, 1.0, 1.0).

#### static Cesium.Cartesian4.packedLength : number
engine/Source/Core/Cartesian4.js 898

The number of elements used to pack the object into an array.

#### static constant Cesium.Cartesian4.UNIT_W : Cartesian4
engine/Source/Core/Cartesian4.js 972

An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 1.0).

#### static constant Cesium.Cartesian4.UNIT_X : Cartesian4
engine/Source/Core/Cartesian4.js 948

An immutable Cartesian4 instance initialized to (1.0, 0.0, 0.0, 0.0).

#### static constant Cesium.Cartesian4.UNIT_Y : Cartesian4
engine/Source/Core/Cartesian4.js 956

An immutable Cartesian4 instance initialized to (0.0, 1.0, 0.0, 0.0).

#### static constant Cesium.Cartesian4.UNIT_Z : Cartesian4
engine/Source/Core/Cartesian4.js 964

An immutable Cartesian4 instance initialized to (0.0, 0.0, 1.0, 0.0).

#### static constant Cesium.Cartesian4.ZERO : Cartesian4
engine/Source/Core/Cartesian4.js 932

An immutable Cartesian4 instance initialized to (0.0, 0.0, 0.0, 0.0).

### Methods

#### clone(result) → Cartesian4
engine/Source/Core/Cartesian4.js 788

Duplicates this Cartesian4 instance.

Name | Type | Description
--- | --- | ---
`result` | Cartesian4 | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Cartesian4 instance if one was not provided.

#### equals(right) → boolean
engine/Source/Core/Cartesian4.js 799

Compares this Cartesian against the provided Cartesian componentwise and returns `true` if they are equal, `false` otherwise.

Name | Type | Description
--- | --- | ---
`right` | Cartesian4 | optional The right hand side Cartesian.

##### Returns:

`true` if they are equal, `false` otherwise.

#### equalsEpsilon(right, relativeEpsilon, absoluteEpsilon) → boolean
engine/Source/Core/Cartesian4.js 813

Compares this Cartesian against the provided Cartesian componentwise and returns `true` if they pass an absolute or relative tolerance test, `false` otherwise.

Name | Type | Default | Description
--- | --- | --- | ---
`right` | Cartesian4 |  | optional The right hand side Cartesian.
`relativeEpsilon` | number | `0` | optional The relative epsilon tolerance to use for equality testing.
`absoluteEpsilon` | number | `relativeEpsilon` | optional The absolute epsilon tolerance to use for equality testing.

##### Returns:

`true` if they are within the provided epsilon, `false` otherwise.

#### toString() → string
engine/Source/Core/Cartesian4.js 827

Creates a string representing this Cartesian in the format '(x, y, z, w)'.

##### Returns:

A string representing the provided Cartesian in the format '(x, y, z, w)'.

#### static Cesium.Cartesian4.abs(cartesian, result) → Cartesian4
engine/Source/Core/Cartesian4.js 626

Computes the absolute value of the provided Cartesian.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The Cartesian whose absolute value is to be computed.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.add(left, right, result) → Cartesian4
engine/Source/Core/Cartesian4.js 519

Computes the componentwise sum of two Cartesians.

Name | Type | Description
--- | --- | ---
`left` | Cartesian4 | The first Cartesian.
`right` | Cartesian4 | The second Cartesian.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.clamp(value, min, max, result) → Cartesian4
engine/Source/Core/Cartesian4.js 318

Constrain a value to lie between two values.

Name | Type | Description
--- | --- | ---
`value` | Cartesian4 | The value to clamp.
`min` | Cartesian4 | The minimum bound.
`max` | Cartesian4 | The maximum bound.
`result` | Cartesian4 | The object into which to store the result.

##### Returns:

The clamped value such that min <= result <= max.

#### static Cesium.Cartesian4.clone(cartesian, result) → Cartesian4
engine/Source/Core/Cartesian4.js 107

Duplicates a Cartesian4 instance.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The Cartesian to duplicate.
`result` | Cartesian4 | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Cartesian4 instance if one was not provided. (Returns undefined if cartesian is undefined)

#### static Cesium.Cartesian4.distance(left, right) → number
engine/Source/Core/Cartesian4.js 381

Computes the 4-space distance between two points.

Name | Type | Description
--- | --- | ---
`left` | Cartesian4 | The first point to compute the distance from.
`right` | Cartesian4 | The second point to compute the distance to.

##### Returns:

The distance between two points.

##### Example:

    // Returns 1.0
    const d = Cesium.Cartesian4.distance(
      new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
      new Cesium.Cartesian4(2.0, 0.0, 0.0, 0.0));

#### static Cesium.Cartesian4.distanceSquared(left, right) → number
engine/Source/Core/Cartesian4.js 405

Computes the squared distance between two points. Comparing squared distances using this function is more efficient than comparing distances using `Cartesian4#distance`.

Name | Type | Description
--- | --- | ---
`left` | Cartesian4 | The first point to compute the distance from.
`right` | Cartesian4 | The second point to compute the distance to.

##### Returns:

The distance between two points.

##### Example:

    // Returns 4.0, not 2.0
    const d = Cesium.Cartesian4.distance(
      new Cesium.Cartesian4(1.0, 0.0, 0.0, 0.0),
      new Cesium.Cartesian4(3.0, 0.0, 0.0, 0.0));

#### static Cesium.Cartesian4.divideByScalar(cartesian, scalar, result) → Cartesian4
engine/Source/Core/Cartesian4.js 585

Divides the provided Cartesian componentwise by the provided scalar.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The Cartesian to be divided.
`scalar` | number | The scalar to divide by.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.divideComponents(left, right, result) → Cartesian4
engine/Source/Core/Cartesian4.js 497

Computes the componentwise quotient of two Cartesians.

Name | Type | Description
--- | --- | ---
`left` | Cartesian4 | The first Cartesian.
`right` | Cartesian4 | The second Cartesian.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.dot(left, right) → number
engine/Source/Core/Cartesian4.js 456

Computes the dot (scalar) product of two Cartesians.

Name | Type | Description
--- | --- | ---
`left` | Cartesian4 | The first Cartesian.
`right` | Cartesian4 | The second Cartesian.

##### Returns:

The dot product.

#### static Cesium.Cartesian4.equals(left, right) → boolean
engine/Source/Core/Cartesian4.js 712

Compares the provided Cartesians componentwise and returns `true` if they are equal, `false` otherwise.

Name | Type | Description
--- | --- | ---
`left` | Cartesian4 | optional The first Cartesian.
`right` | Cartesian4 | optional The second Cartesian.

##### Returns:

`true` if left and right are equal, `false` otherwise.

#### static Cesium.Cartesian4.equalsEpsilon(left, right, relativeEpsilon, absoluteEpsilon) → boolean
engine/Source/Core/Cartesian4.js 750

Compares the provided Cartesians componentwise and returns `true` if they pass an absolute or relative tolerance test, `false` otherwise.

Name | Type | Default | Description
--- | --- | --- | ---
`left` | Cartesian4 |  | optional The first Cartesian.
`right` | Cartesian4 |  | optional The second Cartesian.
`relativeEpsilon` | number | `0` | optional The relative epsilon tolerance to use for equality testing.
`absoluteEpsilon` | number | `relativeEpsilon` | optional The absolute epsilon tolerance to use for equality testing.

##### Returns:

`true` if left and right are within the provided epsilon, `false` otherwise.

#### static Cesium.Cartesian4.fromArray(array, startingIndex, result) → Cartesian4
engine/Source/Core/Cartesian4.js 918

Creates a Cartesian4 from four consecutive elements in an array.

Name | Type | Default | Description
--- | --- | --- | ---
`array` | Array.<number> |  | The array whose four consecutive elements correspond to the x, y, z, and w components, respectively.
`startingIndex` | number | `0` | optional The offset into the array of the first element, which corresponds to the x component.
`result` | Cartesian4 |  | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Cartesian4 instance if one was not provided.

##### Example:

    // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0)
    const v = [1.0, 2.0, 3.0, 4.0];
    const p = Cesium.Cartesian4.fromArray(v);

    // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0) using an offset into an array
    const v2 = [0.0, 0.0, 1.0, 2.0, 3.0, 4.0];
    const p2 = Cesium.Cartesian4.fromArray(v2, 2);

#### static Cesium.Cartesian4.fromColor(color, result) → Cartesian4
engine/Source/Core/Cartesian4.js 85

Creates a Cartesian4 instance from a `Color`. `red`, `green`, `blue`, and `alpha` map to `x`, `y`, `z`, and `w`, respectively.

Name | Type | Description
--- | --- | ---
`color` | Color | The source color.
`result` | Cartesian4 | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Cartesian4 instance if one was not provided.

#### static Cesium.Cartesian4.fromElements(x, y, z, w, result) → Cartesian4
engine/Source/Core/Cartesian4.js 65

Creates a Cartesian4 instance from x, y, z and w coordinates.

Name | Type | Description
--- | --- | ---
`x` | number | The x coordinate.
`y` | number | The y coordinate.
`z` | number | The z coordinate.
`w` | number | The w coordinate.
`result` | Cartesian4 | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Cartesian4 instance if one was not provided.

#### static Cesium.Cartesian4.lerp(start, end, t, result) → Cartesian4
engine/Source/Core/Cartesian4.js 648

Computes the linear interpolation or extrapolation at t using the provided cartesians.

Name | Type | Description
--- | --- | ---
`start` | Cartesian4 | The value corresponding to t at 0.0.
`end` | Cartesian4 | The value corresponding to t at 1.0.
`t` | number | The point along t at which to interpolate.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.magnitude(cartesian) → number
engine/Source/Core/Cartesian4.js 364

Computes the Cartesian's magnitude (length).

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The Cartesian instance whose magnitude is to be computed.

##### Returns:

The magnitude.

#### static Cesium.Cartesian4.magnitudeSquared(cartesian) → number
engine/Source/Core/Cartesian4.js 345

Computes the provided Cartesian's squared magnitude.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The Cartesian instance whose squared magnitude is to be computed.

##### Returns:

The squared magnitude.

#### static Cesium.Cartesian4.maximumByComponent(first, second, result) → Cartesian4
engine/Source/Core/Cartesian4.js 294

Compares two Cartesians and computes a Cartesian which contains the maximum components of the supplied Cartesians.

Name | Type | Description
--- | --- | ---
`first` | Cartesian4 | A cartesian to compare.
`second` | Cartesian4 | A cartesian to compare.
`result` | Cartesian4 | The object into which to store the result.

##### Returns:

A cartesian with the maximum components.

#### static Cesium.Cartesian4.maximumComponent(cartesian) → number
engine/Source/Core/Cartesian4.js 241

Computes the value of the maximum component for the supplied Cartesian.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The cartesian to use.

##### Returns:

The value of the maximum component.

#### static Cesium.Cartesian4.minimumByComponent(first, second, result) → Cartesian4
engine/Source/Core/Cartesian4.js 271

Compares two Cartesians and computes a Cartesian which contains the minimum components of the supplied Cartesians.

Name | Type | Description
--- | --- | ---
`first` | Cartesian4 | A cartesian to compare.
`second` | Cartesian4 | A cartesian to compare.
`result` | Cartesian4 | The object into which to store the result.

##### Returns:

A cartesian with the minimum components.

#### static Cesium.Cartesian4.minimumComponent(cartesian) → number
engine/Source/Core/Cartesian4.js 255

Computes the value of the minimum component for the supplied Cartesian.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The cartesian to use.

##### Returns:

The value of the minimum component.

#### static Cesium.Cartesian4.mostOrthogonalAxis(cartesian, result) → Cartesian4
engine/Source/Core/Cartesian4.js 668

Returns the axis that is most orthogonal to the provided Cartesian.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The Cartesian on which to find the most orthogonal axis.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The most orthogonal axis.

#### static Cesium.Cartesian4.multiplyByScalar(cartesian, scalar, result) → Cartesian4
engine/Source/Core/Cartesian4.js 563

Multiplies the provided Cartesian componentwise by the provided scalar.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The Cartesian to be scaled.
`scalar` | number | The scalar to multiply with.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.multiplyComponents(left, right, result) → Cartesian4
engine/Source/Core/Cartesian4.js 475

Computes the componentwise product of two Cartesians.

Name | Type | Description
--- | --- | ---
`left` | Cartesian4 | The first Cartesian.
`right` | Cartesian4 | The second Cartesian.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.negate(cartesian, result) → Cartesian4
engine/Source/Core/Cartesian4.js 606

Negates the provided Cartesian.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The Cartesian to be negated.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.normalize(cartesian, result) → Cartesian4
engine/Source/Core/Cartesian4.js 422

Computes the normalized form of the supplied Cartesian.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian4 | The Cartesian to be normalized.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.pack(value, array, startingIndex) → Array.<number>|TypedArray
engine/Source/Core/Cartesian4.js 132

Stores the provided instance into the provided array.

Name | Type | Default | Description
--- | --- | --- | ---
`value` | Cartesian4 |  | The value to pack.
`array` | Array.<number> | TypedArray |  | The array to pack into.
`startingIndex` | number | `0` | optional The index into the array at which to start packing the elements.

##### Returns:

The array that was packed into

#### static Cesium.Cartesian4.packArray(array, result) → Array.<number>|TypedArray
engine/Source/Core/Cartesian4.js 180

Flattens an array of Cartesian4s into an array of components.

Name | Type | Description
--- | --- | ---
`array` | Array.<Cartesian4> | The array of cartesians to pack.
`result` | Array.<number> | TypedArray | optional The array onto which to store the result. If this is a typed array, it must have array.length * 4 components, else a `DeveloperError` will be thrown. If it is a regular array, it will be resized to have (array.length * 4) elements.

##### Returns:

The packed array.

#### static Cesium.Cartesian4.packFloat(value, result) → Cartesian4
engine/Source/Core/Cartesian4.js 838

Packs an arbitrary floating point value to 4 values representable using uint8.

Name | Type | Description
--- | --- | ---
`value` | number | A floating point number.
`result` | Cartesian4 | optional The Cartesian4 that will contain the packed float.

##### Returns:

A Cartesian4 representing the float packed to values in x, y, z, and w.

#### static Cesium.Cartesian4.subtract(left, right, result) → Cartesian4
engine/Source/Core/Cartesian4.js 541

Computes the componentwise difference of two Cartesians.

Name | Type | Description
--- | --- | ---
`left` | Cartesian4 | The first Cartesian.
`right` | Cartesian4 | The second Cartesian.
`result` | Cartesian4 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Cartesian4.unpack(array, startingIndex, result) → Cartesian4
engine/Source/Core/Cartesian4.js 156

Retrieves an instance from a packed array.

Name | Type | Default | Description
--- | --- | --- | ---
`array` | Array.<number> | TypedArray |  | The packed array.
`startingIndex` | number | `0` | optional The starting index of the element to be unpacked.
`result` | Cartesian4 |  | optional The object into which to store the result.

##### Returns:

The modified result parameter or a new Cartesian4 instance if one was not provided.

#### static Cesium.Cartesian4.unpackArray(array, result) → Array.<Cartesian4>
engine/Source/Core/Cartesian4.js 212

Unpacks an array of cartesian components into an array of Cartesian4s.

Name | Type | Description
--- | --- | ---
`array` | Array.<number> | TypedArray | The array of components to unpack.
`result` | Array.<Cartesian4> | optional The array onto which to store the result.

##### Returns:

The unpacked array.

Need help? The fastest way to get answers is from the community and team on the Cesium Forum.