| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# csMath3 Class Reference
[Geometry utilities]

Various assorted 3D mathematical functions. More...

`#include <csgeom/math3d.h>`

List of all members.

## Static Public Member Functions
static void | Between (const csVector3 &v1, const csVector3 &v2, csVector3 &v, float pct, float wid)
| Calculates a vector lying a specified distance between two other vectors.
static void | CalcNormal (csVector3 &norm, const csVector3 &v, const csVector3 &u)
| Compute the normal given two (u,v) vectors.
static void | CalcNormal (csVector3 &norm, const csVector3 &v1, const csVector3 &v2, const csVector3 &v3)
| Calculate a plane normal given three vectors.
static void | CalcPlane (const csVector3 &v1, const csVector3 &v2, const csVector3 &v3, csVector3 &normal, float &D)
| Calculate the plane equation given three vectors.
static float | Direction3 (const csVector3 &a, const csVector3 &b, const csVector3 &c)
| Returns < 0 or > 0 depending on the direction of the triangle.
static float | DoubleArea3 (const csVector3 &a, const csVector3 &b, const csVector3 &c)
| Compute twice the area of triangle composed by three points.
static int | FindObserverSides (const csBox3 &box1, const csBox3 &box2, int *sides)
| Find all observer sides on the first box that can see the other box.
static int | OuterPlanes (const csBox3 &box1, const csBox3 &box2, csPlane3 *planes)
| Calculate the set of outer planes between the two boxes.
static bool | PlanesClose (const csPlane3 &p1, const csPlane3 &p2)
| Check if two planes are close together.
static bool | PlanesEqual (const csPlane3 &p1, const csPlane3 &p2)
| Check if two planes are almost equal.
static void | SetMinMax (const csVector3 &v, csVector3 &min, csVector3 &max)
| Set the min and max vector if this vector exceeds their current limits.
static void | SpherePosition (float angle_xz, float angle_vert, csVector3 &pos)
| Given two angles in radians, calculate the position on the sphere around (0,0,0) with radius 1.
static bool | Visible (const csVector3 &p, const csPlane3 &pl)
| Check if the plane is visible from the given point.
static bool | Visible (const csVector3 &p, const csVector3 &t1, const csVector3 &t2, const csVector3 &t3)
| Tests if the front face of a triangle is visible from the given point.
static int | WhichSide3D (const csVector3 &p, const csVector3 &v1, const csVector3 &v2)
| Tests which side of a plane the given 3D point is on.

## Detailed Description

Various assorted 3D mathematical functions.

This is a static class and contains only static member functions.

Definition at line 50 of file math3d.h.

## Member Function Documentation

static void csMath3::Between | ( | const csVector3 & | v1,
|  | const csVector3 & | v2,
|  | csVector3 & | v,
|  | float | pct,
|  | float | wid |
| ) |  |  | `[static]`

Calculates a vector lying a specified distance between two other vectors.

Given vectors v1 and v2, this function will calculate and return vector v lying between them. If pct != -1, vector v will be the point which is pct % of the way from v1 to v2. Otherwise, if pct equals -1, v will be the point along 'v1-v2' which is distance wid from v1.

static void csMath3::CalcNormal | ( | csVector3 & | norm,
|  | const csVector3 & | v,
|  | const csVector3 & | u |
| ) |  |  | `[inline, static]`

Compute the normal given two (u,v) vectors.

This function will calculate the normal to a polygon with two edges represented by v and u. The result is stored in norm.

Definition at line 159 of file math3d.h.

static void csMath3::CalcNormal | ( | csVector3 & | norm,
|  | const csVector3 & | v1,
|  | const csVector3 & | v2,
|  | const csVector3 & | v3 |
| ) |  |  | `[inline, static]`

Calculate a plane normal given three vectors.

This function will calculate the normal to the plane formed by vectors v1, v2, and v3, and store the result in norm.

Definition at line 148 of file math3d.h.

static void csMath3::CalcPlane | ( | const csVector3 & | v1,
|  | const csVector3 & | v2,
|  | const csVector3 & | v3,
|  | csVector3 & | normal,
|  | float & | D |
| ) |  |  | `[inline, static]`

Calculate the plane equation given three vectors.

Given three vectors v1, v2, and v3, forming a plane, this function will calculate the plane equation and return the result in 'normal' and 'D'.

Definition at line 169 of file math3d.h.

static float csMath3::Direction3 | ( | const csVector3 & | a,
|  | const csVector3 & | b,
|  | const csVector3 & | c |
| ) |  |  | `[inline, static]`

Returns < 0 or > 0 depending on the direction of the triangle.

Definition at line 134 of file math3d.h.

References csVector3::x, csVector3::y, and csVector3::z.

static float csMath3::DoubleArea3 | ( | const csVector3 & | a,
|  | const csVector3 & | b,
|  | const csVector3 & | c |
| ) |  |  | `[inline, static]`

Compute twice the area of triangle composed by three points.

This function returns 2 x the area of the triangle formed by the points a, b, and c.

Definition at line 123 of file math3d.h.

References csVector3::Norm().

static int csMath3::FindObserverSides | ( | const csBox3 & | box1,
|  | const csBox3 & | box2,
|  | int * | sides |
| ) |  |  | `[static]`

Find all observer sides on the first box that can see the other box.

Sides are numbered like this: 0=MinX(), 1=MaxX(), 2=MinY(), 3=MaxY(), 4=MinZ(), 5=MaxZ(). The given array should have place for 6 sides. This function returns the number of observer sides.

static int csMath3::OuterPlanes | ( | const csBox3 & | box1,
|  | const csBox3 & | box2,
|  | csPlane3 * | planes |
| ) |  |  | `[static]`

Calculate the set of outer planes between the two boxes.

Is something does not intersect this set of planes then it will not be between the two boxes. The given array of planes should have place for at least eight planes. This function returns the number of planes that are put in 'planes'.

static bool csMath3::PlanesClose | ( | const csPlane3 & | p1,
|  | const csPlane3 & | p2 |
| ) |  |  | `[static]`

Check if two planes are close together.

Two planes are close if there are almost equal OR if the normalized versions are almost equal.

static bool csMath3::PlanesEqual | ( | const csPlane3 & | p1,
|  | const csPlane3 & | p2 |
| ) |  |  | `[inline, static]`

Check if two planes are almost equal.

The function returns true iff each component of the plane equation for one plane is within .001 of the corresponding component of the other plane.

Definition at line 182 of file math3d.h.

References ABS, csPlane3::DD, and csPlane3::norm.

static void csMath3::SetMinMax | ( | const csVector3 & | v,
|  | csVector3 & | min,
|  | csVector3 & | max |
| ) |  |  | `[inline, static]`

Set the min and max vector if this vector exceeds their current limits.

This function will check each component of vector v against the maximum and minimum values specified by min and max. If the limits are exceeded, new min or max values will be set.

Definition at line 110 of file math3d.h.

References csVector3::x, csVector3::y, and csVector3::z.

static void csMath3::SpherePosition | ( | float | angle_xz,
|  | float | angle_vert,
|  | csVector3 & | pos |
| ) |  |  | `[static]`

Given two angles in radians, calculate the position on the sphere around (0,0,0) with radius 1.

The first angle is the angle along the horizontal (x/z) plane. The second angle is the vertical angle.

static bool csMath3::Visible | ( | const csVector3 & | p,
|  | const csPlane3 & | pl |
| ) |  |  | `[inline, static]`

Check if the plane is visible from the given point.

This function does a back-face culling test to see whether the front face of plane pl is visible from point p.

Definition at line 89 of file math3d.h.

References csPlane3::Classify().

static bool csMath3::Visible | ( | const csVector3 & | p,
|  | const csVector3 & | t1,
|  | const csVector3 & | t2,
|  | const csVector3 & | t3 |
| ) |  |  | `[static]`

Tests if the front face of a triangle is visible from the given point.

Visibility test (backface culling) to see if the triangle formed by t1, t2, and t3 is visible from point p.

static int csMath3::WhichSide3D | ( | const csVector3 & | p,
|  | const csVector3 & | v1,
|  | const csVector3 & | v2 |
| ) |  |  | `[inline, static]`

Tests which side of a plane the given 3D point is on.

Returns:
  -1 if point p is left of plane '0-v1-v2', 1 if point p is right of plane '0-v1-v2', or 0 if point p lies on plane '0-v1-v2'. Plane '0-v1-v2' is the plane passing through points <0,0,0>, v1, and v2.

Warning: the result of this function when 'p' is exactly on the plane 0-v1-v2 is undefined. It should return 0 but it will not often do that due to numerical inaccuracies. So you should probably test for this case separately.

Definition at line 65 of file math3d.h.

References csVector3::x, csVector3::y, and csVector3::z.

The documentation for this class was generated from the following file:

- csgeom/math3d.h