Mesh_analyzer
Loading...
Searching...
No Matches
point.h
1#ifndef POINT_H
2#define POINT_H
3
4#include <iostream>
5#include <cmath>
6#include <vector>
7
12struct Point {
13 float x, y, z;
14
15
20 Point() : x(0), y(0), z(0) {}
21
22
29 Point(float x_, float y_) : x(x_), y(y_), z(0) {}
30
31
39 Point(float x_, float y_, float z_) : x(x_), y(y_), z(z_) {}
40
41
47 float length() const;
48
49
56 float distance(const Point& other) const;
57
58
59 // Operator overloads for vector arithmetic
60 Point operator-(const Point& other) const;
61 Point operator+(const Point& other) const;
62 Point operator*(float scalar) const;
63 bool operator==(const Point& other) const;
64 void operator+=(const Point& other);
65 void operator/=(float scalar);
66 void operator*=(float scalar);
67
75 friend std::ostream& operator<<(std::ostream& os, const Point& p);
76};
77
78#endif
A struct representing a point in 3D space.
Definition point.h:12
float distance(const Point &other) const
Calculate the distance between this point and another point.
Definition point.cpp:8
float z
Coordinates of the point.
Definition point.h:13
friend std::ostream & operator<<(std::ostream &os, const Point &p)
Overload the << operator to print the point's coordinates.
Definition point.cpp:48
Point(float x_, float y_)
Construct a new Point object at the specified coordinates (z defaults to 0)
Definition point.h:29
Point(float x_, float y_, float z_)
Construct a new Point object at the specified coordinates.
Definition point.h:39
Point()
Construct a new Point object at the origin.
Definition point.h:20
float length() const
Calculate the length of the vector from the origin to this point.
Definition point.cpp:3