# [−][src]Trait cgmath::EuclideanSpace

    pub trait EuclideanSpace: Copy + Clone where
        Self: Array<Element = Self::Scalar>,
        Self: Add<Self::Diff, Output = Self>,
        Self: Sub<Self::Diff, Output = Self>,
        Self: Sub<Self, Output = Self::Diff>,
        Self: Mul<Self::Scalar, Output = Self>,
        Self: Div<Self::Scalar, Output = Self>,
        Self: Rem<Self::Scalar, Output = Self>, {
        type Scalar: BaseNum;
        type Diff: VectorSpace<Scalar = Self::Scalar>;
        fn origin() -> Self;
        fn from_vec(v: Self::Diff) -> Self;
        fn to_vec(self) -> Self::Diff;
        fn dot(self, v: Self::Diff) -> Self::Scalar;

        fn midpoint(self, other: Self) -> Self { ... }
        fn centroid(points: &[Self]) -> Self { ... }
    }

Points in a Euclidean space with an associated space of displacement vectors.

# Point-Vector distinction

`cgmath` distinguishes between points and vectors in the following way:

- Points are locations relative to an origin
- Vectors are displacements between those points

For example, to find the midpoint between two points, you can write the following:

    use cgmath::Point3;

    let p0 = Point3::new(1.0, 2.0, 3.0);
    let p1 = Point3::new(-3.0, 1.0, 2.0);
    let midpoint: Point3<f32> = p0 + (p1 - p0) * 0.5;

Breaking the expression up, and adding explicit types makes it clearer to see what is going on:

    let dv: Vector3<f32> = p1 - p0;
    let half_dv: Vector3<f32> = dv * 0.5;
    let midpoint: Point3<f32> = p0 + half_dv;

## Converting between points and vectors

Points can be converted to and from displacement vectors using the `EuclideanSpace::{from_vec, to_vec}` methods. Note that under the hood these are implemented as inlined a type conversion, so should not have any performance implications.

## References

- CGAL 4.7 - 2D and 3D Linear Geometry Kernel: 3.1 Points and Vectors
- What is the difference between a point and a vector

## Associated Types

### `type Scalar: BaseNum`

The associated scalar over which the space is defined.

Due to the equality constraints demanded by `Self::Diff`, this is effectively just an alias to `Self::Diff::Scalar`.

### `type Diff: VectorSpace<Scalar = Self::Scalar>`

The associated space of displacement vectors.

Loading content...

## Required methods

### `fn origin() -> Self`

The point at the origin of the Euclidean space.

### `fn from_vec(v: Self::Diff) -> Self`

Convert a displacement vector to a point.

This can be considered equivalent to the addition of the displacement vector `v` to to `Self::origin()`.

### `fn to_vec(self) -> Self::Diff`

Convert a point to a displacement vector.

This can be seen as equivalent to the displacement vector from `Self::origin()` to `self`.

### `fn dot(self, v: Self::Diff) -> Self::Scalar`

This is a weird one, but its useful for plane calculations.

Loading content...

## Provided methods

### `fn midpoint(self, other: Self) -> Self`

Returns the middle point between two other points.

    use cgmath::prelude::*;
    use cgmath::Point3;

    let p = Point3::midpoint(
        Point3::new(1.0, 2.0, 3.0),
        Point3::new(3.0, 1.0, 2.0),
    );

### `fn centroid(points: &[Self]) -> Self`

Returns the average position of all points in the slice.

    use cgmath::prelude::*;
    use cgmath::Point2;

    let triangle = [
        Point2::new(1.0, 1.0),
        Point2::new(2.0, 3.0),
        Point2::new(3.0, 1.0),
    ];

    let centroid = Point2::centroid(&triangle);

Loading content...

## Implementors

### `impl<S: BaseNum> EuclideanSpace for Point1<S>`[src]

#### `type Scalar = S`

#### `type Diff = Vector1<S>`

#### `fn origin() -> Point1<S>`[src]

#### `fn from_vec(v: Vector1<S>) -> Point1<S>`[src]

#### `fn to_vec(self) -> Vector1<S>`[src]

#### `fn dot(self, v: Vector1<S>) -> S`[src]

### `impl<S: BaseNum> EuclideanSpace for Point2<S>`[src]

#### `type Scalar = S`

#### `type Diff = Vector2<S>`

#### `fn origin() -> Point2<S>`[src]

#### `fn from_vec(v: Vector2<S>) -> Point2<S>`[src]

#### `fn to_vec(self) -> Vector2<S>`[src]

#### `fn dot(self, v: Vector2<S>) -> S`[src]

### `impl<S: BaseNum> EuclideanSpace for Point3<S>`[src]

#### `type Scalar = S`

#### `type Diff = Vector3<S>`

#### `fn origin() -> Point3<S>`[src]

#### `fn from_vec(v: Vector3<S>) -> Point3<S>`[src]

#### `fn to_vec(self) -> Vector3<S>`[src]

#### `fn dot(self, v: Vector3<S>) -> S`[src]

Loading content...

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)