This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/geo/Point3.h
kazu 51cab55d37 refactored the new floorplan
new helper methods/operator toe geo classes
2016-05-24 17:01:56 +02:00

82 lines
2.0 KiB
C++

#ifndef POINT3_H
#define POINT3_H
#include "../Assertions.h"
#include <cmath>
#include "Point2.h"
/**
* 3D Point
*/
struct Point3 {
float x;
float y;
float z;
/** ctor */
Point3() : x(0), y(0), z(0) {;}
/** ctor */
Point3(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
Point3 operator + (const Point3& o) const {return Point3(x+o.x, y+o.y, z+o.z);}
Point3 operator - (const Point3& o) const {return Point3(x-o.x, y-o.y, z-o.z);}
Point3 operator * (const Point3& o) const {return Point3(x*o.x, y*o.y, z*o.z);}
Point3 operator * (const float v) const {return Point3(v*x, v*y, v*z);}
Point3 operator / (const float v) const {return Point3(x/v, y/v, z/v);}
Point3& operator *= (const float v) {x*=v; y*=v; z*=v; return *this;}
Point3& operator /= (const float v) {x/=v; y/=v; z/=v; return *this;}
Point3& operator += (const Point3& o) {x+=o.x; y+=o.y; z+=o.z; return *this;}
Point3& operator -= (const Point3& o) {x-=o.x; y-=o.y; z-=o.z; return *this;}
bool operator < (const Point3& o) const {return x<o.x && y<o.y && z<o.z;}
bool operator == (const Point3& o) const {return x==o.x && y==o.y && z==o.z;}
bool operator != (const Point3& o) const {return x!=o.x || y!=o.y || z!=o.z;}
Point2 xy() const {return Point2(x,y);}
/** read-only array access */
float operator [] (const int idx) const {
Assert::isBetween(idx, 0, 2, "index out of bounds");
if (0 == idx) {return x;}
if (1 == idx) {return y;}
return z;
}
/** get the distance between this point and the other one */
float getDistance(const Point3& o) const {
const float dx = x - o.x;
const float dy = y - o.y;
const float dz = z - o.z;
return std::sqrt(dx*dx + dy*dy + dz*dz);
}
float length() const {return std::sqrt(x*x + y*y + z*z);}
float length(const float norm) const {
return std::pow(
(std::pow(std::abs(x),norm) +
std::pow(std::abs(y),norm) +
std::pow(std::abs(z),norm)
), 1.0f/norm);
}
};
#endif // POINT3_H