# Triangle

Artifact: [androidx.ink:ink-geometry](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/geometry/Triangle.kt+class:androidx.ink.geometry.Triangle) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

*** ** * ** ***


```
public abstract class Triangle
```

<br />

Known direct subclasses [ImmutableTriangle](https://developer.android.com/reference/androidx/ink/geometry/ImmutableTriangle), [MutableTriangle](https://developer.android.com/reference/androidx/ink/geometry/MutableTriangle)

|---|---|
| `https://developer.android.com/reference/androidx/ink/geometry/ImmutableTriangle` | An immutable triangle, defined by its three corners `https://developer.android.com/reference/androidx/ink/geometry/ImmutableTriangle#(androidx.ink.geometry.Vec,androidx.ink.geometry.Vec,androidx.ink.geometry.Vec)`, `https://developer.android.com/reference/androidx/ink/geometry/ImmutableTriangle#(androidx.ink.geometry.Vec,androidx.ink.geometry.Vec,androidx.ink.geometry.Vec)` and `https://developer.android.com/reference/androidx/ink/geometry/ImmutableTriangle#(androidx.ink.geometry.Vec,androidx.ink.geometry.Vec,androidx.ink.geometry.Vec)` in order. |
| `https://developer.android.com/reference/androidx/ink/geometry/MutableTriangle` | Represents a mutable triangle, defined by its three corners `https://developer.android.com/reference/androidx/ink/geometry/MutableTriangle#p0()`, `https://developer.android.com/reference/androidx/ink/geometry/MutableTriangle#p1()` and `https://developer.android.com/reference/androidx/ink/geometry/MutableTriangle#p2()` in order. |

*** ** * ** ***

A triangle defined by its three corners `https://developer.android.com/reference/androidx/ink/geometry/Triangle#p0()`, `https://developer.android.com/reference/androidx/ink/geometry/Triangle#p1()` and `https://developer.android.com/reference/androidx/ink/geometry/Triangle#p2()`. The order of these points matter - a triangle with p0, p1, p2 is not the same as the permuted p1, p0, p2, or even the rotated p2, p0, p1.

A `https://developer.android.com/reference/androidx/ink/geometry/Triangle` may be degenerate, meaning it is constructed with its 3 points colinear. One way that a `https://developer.android.com/reference/androidx/ink/geometry/Triangle` may be degenerate is if two or three of its points are at the same location (coincident).

This is a read-only interface that has mutable and immutable implementations. See `https://developer.android.com/reference/androidx/ink/geometry/MutableTriangle` and `https://developer.android.com/reference/androidx/ink/geometry/ImmutableTriangle`.

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableBox` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeBoundingBox()()` Returns the minimum bounding box containing the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableBox` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeBoundingBox(androidx.ink.geometry.MutableBox)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableBox outBox)` Populates `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeBoundingBox(androidx.ink.geometry.MutableBox)` with the minimum bounding box containing the `https://developer.android.com/reference/androidx/ink/geometry/Triangle` and returns `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeBoundingBox(androidx.ink.geometry.MutableBox)`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableSegment` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 2) int index)` Returns the segment of the Triangle between the point at `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int)` and the point at `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int)` + 1 modulo 3. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableSegment` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int,androidx.ink.geometry.MutableSegment)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 2) int index, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/MutableSegment outSegment )` Fills `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int,androidx.ink.geometry.MutableSegment)` with the segment of the Triangle between the point at `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int,androidx.ink.geometry.MutableSegment)` and the point at `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int,androidx.ink.geometry.MutableSegment)` + 1 modulo 3. |
| `final float` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeSignedArea()()` Return the signed area of the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`. |
| `final boolean` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#contains(androidx.ink.geometry.Vec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec point)` Returns true if the given point is contained within the Triangle. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#getP0()()` One of the three points that define the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#getP1()()` One of the three points that define the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Vec` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#getP2()()` One of the three points that define the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`. |
| `final boolean` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#isAlmostEqual(androidx.ink.geometry.Triangle,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/Triangle other, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float tolerance )` |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/ImmutableTriangle` | `https://developer.android.com/reference/androidx/ink/geometry/Triangle#toImmutable()()` Returns an immutable copy of this object. |

## Public methods

### computeBoundingBox

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull ImmutableBox computeBoundingBox()
```

Returns the minimum bounding box containing the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`.

### computeBoundingBox

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull MutableBox computeBoundingBox(@NonNull MutableBox outBox)
```

Populates `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeBoundingBox(androidx.ink.geometry.MutableBox)` with the minimum bounding box containing the `https://developer.android.com/reference/androidx/ink/geometry/Triangle` and returns `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeBoundingBox(androidx.ink.geometry.MutableBox)`.

### computeEdge

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull ImmutableSegment computeEdge(@IntRange(from = 0, to = 2) int index)
```

Returns the segment of the Triangle between the point at `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int)` and the point at `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int)` + 1 modulo 3.

### computeEdge

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull MutableSegment computeEdge(
    @IntRange(from = 0, to = 2) int index,
    @NonNull MutableSegment outSegment
)
```

Fills `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int,androidx.ink.geometry.MutableSegment)` with the segment of the Triangle between the point at `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int,androidx.ink.geometry.MutableSegment)` and the point at `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int,androidx.ink.geometry.MutableSegment)` + 1 modulo 3. Returns `https://developer.android.com/reference/androidx/ink/geometry/Triangle#computeEdge(kotlin.Int,androidx.ink.geometry.MutableSegment)`.

### computeSignedArea

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final float computeSignedArea()
```

Return the signed area of the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`. If the `https://developer.android.com/reference/androidx/ink/geometry/Triangle` is degenerate, meaning its 3 points are all colinear, then the result will be zero. If its points wind in a positive direction (as defined by `https://developer.android.com/reference/androidx/ink/geometry/Angle`), then the result will be positive. Otherwise, it will be negative.

### contains

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final boolean contains(@NonNull Vec point)
```

Returns true if the given point is contained within the Triangle. Points that lie exactly on the Triangle's boundary are considered to be contained.

### getP0

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public abstract @NonNull Vec getP0()
```

One of the three points that define the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`.

### getP1

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public abstract @NonNull Vec getP1()
```

One of the three points that define the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`.

### getP2

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public abstract @NonNull Vec getP2()
```

One of the three points that define the `https://developer.android.com/reference/androidx/ink/geometry/Triangle`.

### isAlmostEqual

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final boolean isAlmostEqual(
    @NonNull Triangle other,
    @FloatRange(from = 0.0) float tolerance
)
```

### toImmutable

Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

```
public abstract @NonNull ImmutableTriangle toImmutable()
```

Returns an immutable copy of this object. This will return itself if called on an immutable instance.