Point3 Class Reference

Point3 Class Reference
+ Related help topics:

#include <point3.h>

Class Description

See also
Class IPoint3, Class DPoint3, Class Matrix3.

Description:
This class describes a 3D point using float x, y and z coordinates. Methods are provided to add and subtract points, multiply and divide by scalars, and element by element multiply and divide two points.

This class is also frequently used to simply store three floating point values that may not represent a point. For example, a color value where x=red, y=green, and z=blue. For color, the range of values is 0.0 to 1.0, where 0 is 0 and 1.0 is 255. All methods are implemented by the system.

Note: In 3ds Max, all vectors are assumed to be row vectors. Under this assumption, multiplication of a vector with a matrix can be written either way (Matrix*Vector or Vector*Matrix), for ease of use, and the result is the same – the (row) vector transformed by the matrix.
Data Members:
float x, y, z;

The x, y and z components of the point.

static const Point3 Origin;

This data member is available in release 3.0 and later only.

This is equivalent to Point3(0.0f, 0.0f, 0.0f);

static const Point3 XAxis;

This data member is available in release 3.0 and later only.

This is equivalent to Point3(1.0f, 0.0f, 0.0f);

static const Point3 YAxis;

This data member is available in release 3.0 and later only.

This is equivalent to Point3(0.0f, 1.0f, 0.0f);

static const Point3 ZAxis;

This data member is available in release 3.0 and later only.

This is equivalent to Point3(0.0f, 0.0f, 1.0f);
+ Inheritance diagram for Point3:

Public Member Functions

 Point3 ()=default
 Initializes all vector components to zero. More...
 
 Point3 (float X, float Y, float Z)
 
 Point3 (double X, double Y, double Z)
 
 Point3 (int X, int Y, int Z)
 
 Point3 (const Point3 &a)
 
 Point3 (Point3 &&)=default
 
Point3operator= (const Point3 &)=default
 
Point3operator= (Point3 &&)=default
 
 Point3 (const float af[3])
 
 Point3 (const Color &c)
 
 Point3 (Color &&c)
 
 Point3 (const AColor &c)
 
 Point3 (AColor &&c)
 
 Point3 (const Point4 &p)
 
 Point3 (Point4 &&p)
 
float & operator[] (int i)
 
const float & operator[] (int i) const
 
 operator float * ()
 
Point3 operator- () const
 
Point3 operator+ () const
 
float Length () const
 
float FLength () const
 
float LengthSquared () const
 
int MaxComponent () const
 
int MinComponent () const
 
Point3 Normalize () const
 
Point3 FNormalize () const
 
Point3operator-= (const Point3 &)
 
Point3operator+= (const Point3 &)
 
Point3operator*= (float)
 
Point3operator/= (float)
 
Point3operator*= (const Point3 &)
 
Point3Set (float X, float Y, float Z)
 
int operator== (const Point3 &p) const
 
int operator!= (const Point3 &p) const
 
int Equals (const Point3 &p, float epsilon=1E-6f) const
 
Point3Unify ()
 
float LengthUnify ()
 
Point3 operator- (const Point3 &) const
 
Point3 operator+ (const Point3 &) const
 
Point3 operator/ (const Point3 &) const
 
Point3 operator* (const Point3 &) const
 
Point3 operator^ (const Point3 &) const
 
float operator% (const Point3 &) const
 
Point2 XY () const
 Converts this Point3 into a Point2 using the X and Y components. Useful for passing a Point3 where a Point2 is expected. More...
 

Public Attributes

float x = 0.f
 
float y = 0.f
 
float z = 0.f
 

Static Public Attributes

static const Point3 Origin
 
static const Point3 XAxis
 
static const Point3 YAxis
 
static const Point3 ZAxis
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Constructor & Destructor Documentation

Point3 ( )
default

Initializes all vector components to zero.

Point3 ( float  X,
float  Y,
float  Z 
)
inline
Remarks
Constructor. x, y, and z are initialized to the values specified.
66  {
67  x = X;
68  y = Y;
69  z = Z;
70  }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3 ( double  X,
double  Y,
double  Z 
)
inline
Remarks
Constructor. x, y, and z are initialized to the specified values (cast as floats).
72  {
73  x = static_cast<float>(X);
74  y = static_cast<float>(Y);
75  z = static_cast<float>(Z);
76  }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3 ( int  X,
int  Y,
int  Z 
)
inline
Remarks
Constructor. x, y, and z are initialized to the specified values (cast as floats).
78  {
79  x = static_cast<float>(X);
80  y = static_cast<float>(Y);
81  z = static_cast<float>(Z);
82  }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3 ( const Point3 a)
inline
Remarks
Constructor. x, y, and z are initialized to the specified Point3.
84  {
85  x = a.x;
86  y = a.y;
87  z = a.z;
88  }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3 ( Point3 &&  )
default
Remarks
Move Constructor. x, y, and z are initialized to the specified Point3.
Point3 ( const float  af[3])
inline
Remarks
Constructor. x, y, and z are initialized to af[0], af[1], and af[2] respectively.
99  {
100  x = af[0];
101  y = af[1];
102  z = af[2];
103  }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3 ( const Color c)
Remarks
Color Constructor. x = r, y = g, and z = b.
Point3 ( Color &&  c)
Point3 ( const AColor c)
Remarks
AColor Constructor. x = r, y = g, and z = b.
Point3 ( AColor &&  c)
Point3 ( const Point4 p)
Remarks
Point4 Constructor. x = x, y = y, and z = z.
Point3 ( Point4 &&  p)

Member Function Documentation

Point3& operator= ( const Point3 )
default
Remarks
Copy Assignement Operator. x, y, and z are initialized to the specified Point3.
Point3& operator= ( Point3 &&  )
default
Remarks
Move Assignement Operator. x, y, and z are initialized to the specified Point3.
float& operator[] ( int  i)
inline
Remarks
Allows access to x, y and z using the subscript operator.
Returns
An value for i of 0 will return x, 1 will return y, 2 will return z.
124  {
125  DbgAssert((i >= 0) && (i <= 2));
126  return (&x)[i];
127  }
float x
Definition: point3.h:59
#define DbgAssert(expr)
Definition: assert1.h:72
const float& operator[] ( int  i) const
inline
Remarks
Allows access to x, y and z using the subscript operator.
Returns
An value for i of 0 will return x, 1 will return y, 2 will return z.
131  {
132  DbgAssert((i >= 0) && (i <= 2));
133  return (&x)[i];
134  }
float x
Definition: point3.h:59
#define DbgAssert(expr)
Definition: assert1.h:72
operator float * ( )
inline
Remarks
Conversion function. Returns the address of the Point3.x
138 { return (&x); }
float x
Definition: point3.h:59
Point3 operator- ( ) const
inline
Remarks
Unary - operator. Negates x, y and z.
142 { return (Point3(-x, -y, -z)); }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3()=default
Initializes all vector components to zero.
Point3 operator+ ( ) const
inline
Remarks
Unary +. Returns the Point3.
144 { return *this; }
float Length ( ) const
inline
Remarks
Returns the 'Length' of this point (vector). This is:

sqrt(v.x*v.x+v.y*v.y+v.z*v.z)
258 { return sqrt(x * x + y * y + z * z); }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
float FLength ( ) const
inline
Remarks
Returns the 'Length' of this point (vector) using a faster assembly language implementation for square root. This is:

Sqrt(v.x*v.x+v.y*v.y+v.z*v.z)
260 { return Sqrt(x * x + y * y + z * z); }
float y
Definition: point3.h:60
float Sqrt(float arg)
Definition: gfloat.h:76
float z
Definition: point3.h:61
float x
Definition: point3.h:59
__forceinline float LengthSquared ( ) const
Remarks
The 'Length' squared of this point. This is v.x*v.x+v.y*v.y+v.z*v.z.
262 { return (x * x + y * y + z * z); }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
int MaxComponent ( ) const
int MinComponent ( ) const
Point3 Normalize ( ) const
Point3 FNormalize ( ) const
__forceinline Point3 & operator-= ( const Point3 a)
inline
Remarks
Subtracts a Point3 from this Point3.
270  {
271  x -= a.x;
272  y -= a.y;
273  z -= a.z;
274  return *this;
275 }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
__forceinline Point3 & operator+= ( const Point3 a)
inline
Remarks
Adds a Point3 to this Point3.
277  {
278  x += a.x;
279  y += a.y;
280  z += a.z;
281  return *this;
282 }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
__forceinline Point3 & operator*= ( float  f)
inline
Remarks
Multiplies this Point3 by a floating point value.
284  {
285  x *= f;
286  y *= f;
287  z *= f;
288  return *this;
289 }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
__forceinline Point3 & operator/= ( float  f)
inline
Remarks
Divides this Point3 by a floating point value.
291  {
292  DbgAssert(f != 0.0f);
293  float invF = 1.0f / f; // Mimic 2019 behavior
294  x *= invF;
295  y *= invF;
296  z *= invF;
297  return *this;
298 }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
#define DbgAssert(expr)
Definition: assert1.h:72
__forceinline Point3 & operator*= ( const Point3 a)
inline
Remarks
Element-by-element multiplication of two Point3s:

(x*x, y*y, z*z).
300  {
301  x *= a.x;
302  y *= a.y;
303  z *= a.z;
304  return *this;
305 }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
__forceinline Point3 & Set ( float  X,
float  Y,
float  Z 
)
inline
307  {
308  x = X;
309  y = Y;
310  z = Z;
311  return *this;
312 }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
int operator== ( const Point3 p) const
inline
Remarks
Equality operator. Test for equality between two Point3's.
Returns
Nonzero if the Point3's are equal; otherwise 0.
180 { return ((p.x == x) && (p.y == y) && (p.z == z)); }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
int operator!= ( const Point3 p) const
inline
181 { return ((p.x != x) || (p.y != y) || (p.z != z)); }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
int Equals ( const Point3 p,
float  epsilon = 1E-6f 
) const
Point3& Unify ( )
float LengthUnify ( )
__forceinline Point3 operator- ( const Point3 b) const
inline
Remarks
Subtracts a Point3 from a Point3.
314 { return (Point3(x - b.x, y - b.y, z - b.z)); }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3()=default
Initializes all vector components to zero.
__forceinline Point3 operator+ ( const Point3 b) const
inline
Remarks
Adds a Point3 to a Point3.
316 { return (Point3(x + b.x, y + b.y, z + b.z)); }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3()=default
Initializes all vector components to zero.
__forceinline Point3 operator/ ( const Point3 b) const
inline
Remarks
Divides a Point3 by a Point3 element by element.
318  {
319  assert(b.x != 0.0f && b.y != 0.0f && b.z != 0.0f);
320  return Point3(x / b.x, y / b.y, z / b.z);
321 }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3()=default
Initializes all vector components to zero.
#define assert(expr)
Definition: assert1.h:71
__forceinline Point3 operator* ( const Point3 b) const
inline
Remarks
Multiplies a Point3 by a Point3 element by element.

(x*x, y*y, z*z).
323 { return Point3(x * b.x, y * b.y, z * b.z); }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
Point3()=default
Initializes all vector components to zero.
Point3 operator^ ( const Point3 ) const
Remarks
The cross product of two Point3's (vectors).
Returns
The cross product of two Point3's.
__forceinline float operator% ( const Point3 b) const
inline
325 { return (x * b.x + y * b.y + z * b.z); }
float y
Definition: point3.h:60
float z
Definition: point3.h:61
float x
Definition: point3.h:59
__forceinline Point2 XY ( ) const

Converts this Point3 into a Point2 using the X and Y components. Useful for passing a Point3 where a Point2 is expected.

327 { return Point2(x, y); }
float y
Definition: point3.h:60
float x
Definition: point3.h:59
Definition: point2.h:43

Member Data Documentation

float x = 0.f
float y = 0.f
float z = 0.f
const Point3 Origin
static
const Point3 XAxis
static
const Point3 YAxis
static
const Point3 ZAxis
static