Point.h

Note

The documentation on this page was automatically extracted from the DOLFIN C++ code and may need to be edited or expanded.

class Point

A Point represents a point in \(\mathbb{R}^3\) with coordinates \(x, y, z,\) or alternatively, a vector in \(\mathbb{R}^3\), supporting standard operations like the norm, distances, scalar and vector products etc.

Point(const double x = 0.0, const double y = 0.0, const double z = 0.0)

Create a point at (x, y, z). Default value (0, 0, 0).

Arguments
x (double)
The x-coordinate.
y (double)
The y-coordinate.
z (double)
The z-coordinate.
Point(std::size_t dim, const double *x)

Create point from array

Arguments
dim (std::size_t)
Dimension of the array.
x (double)
The array to create a Point from.
Point(const Array<double> &x)

Create point from Array

Arguments
x (Array<double>)
Array of coordinates.
Point(const Point &p)

Copy constructor

Arguments
p (Point)
The object to be copied.
double &operator[](std::size_t i)

Return address of coordinate in direction i

Arguments
i (std::size_t)
Direction.
Returns
double
Address of coordinate in the given direction.
double operator[](std::size_t i) const

Return coordinate in direction i

Arguments
i (std::size_t)
Direction.
Returns
double
The coordinate in the given direction.
double x() const

Return x-coordinate

Returns
double
The x-coordinate.
double y() const

Return y-coordinate

Returns
double
The y-coordinate.
double z() const

Return z-coordinate

Returns
double
The z-coordinate.
double *coordinates()

Return coordinate array

Returns
list of doubles
The coordinates.
const double *coordinates() const

Return coordinate array (const. version)

Returns
list of doubles
The coordinates.
Point operator+(const Point &p) const

Compute sum of two points

Point operator-(const Point &p) const

Compute difference of two points

const Point &operator+=(const Point &p)

Add given point

const Point &operator-=(const Point &p)

Subtract given point

Point operator-()

Unary minus

Point operator*(double a) const

Multiplication with scalar

const Point &operator*=(double a)

Incremental multiplication with scalar

Point operator/(double a) const

Division by scalar

const Point &operator/=(double a)

Incremental division by scalar

const Point &operator=(const Point &p)

Assignment operator

double squared_distance(const Point &p) const

Compute squared distance to given point

Arguments
p (Point)
The point to compute distance to.
Returns
double
The squared distance.
Example
Point p1(0, 4, 0);
Point p2(2, 0, 4);
info("%g", p1.squared_distance(p2));

output:

6
double distance(const Point &p) const

Compute distance to given point

Arguments
p (Point)
The point to compute distance to.
Returns
double
The distance.
Example
Point p1(0, 4, 0);
Point p2(2, 0, 4);
info("%g", p1.distance(p2));

output:

6
double norm() const

Compute norm of point representing a vector from the origin

Returns
double
The (Euclidean) norm of the vector from the origin to the point.
Example
Point p(1.0, 2.0, 2.0);
info("%g", p.norm());

output:

3
double squared_norm() const

Compute norm of point representing a vector from the origin

Returns
double
The squared (Euclidean) norm of the vector from the origin of the point.
Example
Point p(1.0, 2.0, 2.0);
info("%g", p.squared_norm());

output:

9
const Point cross(const Point &p) const

Compute cross product with given vector

Arguments
p (Point)
Another point.
Returns
Point
The cross product.
double dot(const Point &p) const

Compute dot product with given vector

Arguments
p (Point)
Another point.
Returns
double
The dot product.
Example
Point p1(1.0, 4.0, 8.0);
Point p2(2.0, 0.0, 0.0);
info("%g", p1.dot(p2));

output:

2
Point rotate(const Point &a, double theta) const

Rotate around a given axis

Arguments
a (Point)
The axis to rotate around. Must be unit length.
theta (_double_)
The rotation angle.
Returns
Point
The rotated point.
std::string str(bool verbose = false) const

Return informal string representation (pretty-print)

Arguments
verbose (bool)
Flag to turn on additional output.
Returns
std::string
An informal representation of the function space.
Point operator*(double a, const Point &p)

Multiplication with scalar