MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
point3.h
Go to the documentation of this file.
1 /*
2  This file is part of the MinGfx Project.
3 
4  Copyright (c) 2017,2018 Regents of the University of Minnesota.
5  All Rights Reserved.
6 
7  Original Author(s) of this File:
8  Dan Keefe, 2018, University of Minnesota
9 
10  Author(s) of Significant Updates/Modifications to the File:
11  ...
12  */
13 
14 #ifndef SRC_POINT3_H_
15 #define SRC_POINT3_H_
16 
17 #include <iostream>
18 #include <vector>
19 
20 namespace mingfx {
21 
23 #define MINGFX_MATH_EPSILON 1e-8
24 
25 // forward declaration
26 class Vector3;
27 
28 
52 class Point3 {
53 public:
55  Point3();
56 
59  Point3(float x, float y, float z);
60 
62  Point3(float *p);
63 
65  Point3(const Point3& p);
66 
68  virtual ~Point3();
69 
71  bool operator==(const Point3& p) const;
72 
74  bool operator!=(const Point3& p) const;
75 
77  Point3& operator=(const Point3& p);
78 
80  float operator[](const int i) const;
81 
89  float& operator[](const int i);
90 
93  float x() const { return p[0]; }
94 
97  float y() const { return p[1]; }
98 
101  float z() const { return p[2]; }
102 
104  float w() const { return 1.0; }
105 
107  const float * value_ptr() const;
108 
109 
113  Point3 Lerp(const Point3 &b, float alpha) const;
114 
117  float DistanceToPlane(const Point3 &plane_origin, const Vector3 &plane_normal);
118 
121  Point3 ClosestPointOnPlane(const Point3 &plane_origin, const Vector3 &plane_normal);
122 
124  Point3 ClosestPoint(const std::vector<Point3> &point_list);
125 
126 
127 
129  static const Point3& Origin();
130 
132  static const Point3& Zero();
133 
135  static const Point3& One();
136 
139  static Point3 Lerp(const Point3 &a, const Point3 &b, float alpha);
140 
141 
142 
143 private:
144  float p[3];
145 };
146 
147 
148 std::ostream & operator<< ( std::ostream &os, const Point3 &p);
149 std::istream & operator>> ( std::istream &is, Point3 &p);
150 
151 
152 } // namespace
153 
154 #endif
A 3D Point with floating point coordinates, used for storing vertices and all sorts of other 3D graph...
Definition: point3.h:52
Point3(float *p)
Constructs a point given a pointer to x,y,z data.
float y() const
Read only access to the y coordinate. Can also use my_point[1]. Use the my_point[1] = 1....
Definition: point3.h:97
static Point3 Lerp(const Point3 &a, const Point3 &b, float alpha)
Linear interpolation between two points. Alpha=0.0 returns 'a' and alpha=1.0 returns 'b',...
Point3 Lerp(const Point3 &b, float alpha) const
Linear interpolation between this point and another. Alpha=0.0 returns this point,...
Point3(const Point3 &p)
Copy constructor for point.
Point3(float x, float y, float z)
Constructs a point given (x,y,z,1), where the 1 comes from the use of homogeneous coordinates in comp...
static const Point3 & One()
(1,1,1) - a shortcut for a special point that is frequently needed
float operator[](const int i) const
Read only access to the ith coordinate of the point.
float & operator[](const int i)
Returns a reference to the ith coordinate of the point. Use this accessor if you wish to set the coor...
Point3 & operator=(const Point3 &p)
Assignment operator.
static const Point3 & Zero()
(0,0,0) - a shortcut for a special point that is frequently needed
Point3 ClosestPoint(const std::vector< Point3 > &point_list)
Given a list of points, returns the closest in the last to the current point.
virtual ~Point3()
Point destructor.
bool operator==(const Point3 &p) const
Check for "equality", taking floating point imprecision into account.
float w() const
In homogeneous coordinates, the w coordinate for all points is 1.0.
Definition: point3.h:104
float x() const
Read only access to the x coordinate. Can also use my_point[0]. Use the my_point[0] = 1....
Definition: point3.h:93
float z() const
Read only access to the z coordinate. Can also use my_point[2]. Use the my_point[2] = 1....
Definition: point3.h:101
bool operator!=(const Point3 &p) const
Check for "inequality", taking floating point imprecision into account.
Point3 ClosestPointOnPlane(const Point3 &plane_origin, const Vector3 &plane_normal)
Returns the perpendicular projection of this point onto a plane defined by a point and a normal.
Point3()
Default point at the origin.
static const Point3 & Origin()
(0,0,0) - a shortcut for a special point that is frequently needed
const float * value_ptr() const
Returns a const pointer to the raw data array.
float DistanceToPlane(const Point3 &plane_origin, const Vector3 &plane_normal)
Returns the shortest (i.e., perpendicular) distance from this point to a plane defined by a point and...
A 3D Vector with floating point coordinates, used for storing normals and all sorts of other 3D graph...
Definition: vector3.h:62
Namespace for the MinGfx Toolkit.
Definition: aabb.h:21
std::ostream & operator<<(std::ostream &os, const Color &c)
std::istream & operator>>(std::istream &is, Color &c)