This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
3d_geometric_shapes [2023/04/13 19:46] max created |
3d_geometric_shapes [2023/04/13 19:56] (current) max added remaining shapes |
||
---|---|---|---|
Line 9: | Line 9: | ||
* Sphere | * Sphere | ||
* Triangle | * Triangle | ||
+ | |||
===== AABB ===== | ===== AABB ===== | ||
Line 36: | Line 37: | ||
+ | ===== Line ===== | ||
+ | The Line struct represents a line in 3D space with a start and end point. | ||
+ | It has two fields: | ||
+ | - start: a Point (x,y,z) representing the starting point of the line | ||
+ | - end: a Point (x,y,z) representing the ending point of the line | ||
+ | |||
+ | It also has two constructors: | ||
+ | - Line(): sets both start and end points to (0,0,0) | ||
+ | - Line(const Point& s, const Point& e): sets the start point to the given point s and the end point to the given point e | ||
+ | |||
+ | The struct provides two static methods for getting the length of a line: | ||
+ | - Length(const Line& line): returns the length of the given line using the Magnitude() method of the vector between its start and end points | ||
+ | - LengthFast(const Line& line): returns an approximation of the length of the given line using the MagnitudeFast() method of the vector between its start and end points, which trades accuracy for speed. | ||
+ | |||
+ | Example usage: | ||
+ | <code cpp> | ||
+ | Line line1; // creates a line with start and end points at (0,0,0) | ||
+ | Line line2(Point(1, | ||
+ | float length = Line:: | ||
+ | float lengthFast = Line:: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Oriented Box ===== | ||
+ | The OrientedBox struct represents a box-shaped object in 3D space, oriented in any direction. | ||
+ | |||
+ | It has three fields: | ||
+ | - position: a Point (x,y,z) representing the position of the center of the box in 3D space | ||
+ | - size: a Vector3 (x,y,z) representing the dimensions of the box (length, width, height) | ||
+ | - orientation: | ||
+ | |||
+ | It has three constructors: | ||
+ | - OrientedBox(): | ||
+ | - OrientedBox(const Point& p, const Vector3& | ||
+ | - OrientedBox(const Point& p, const Vector3& | ||
+ | |||
+ | Example usage: | ||
+ | <code cpp> | ||
+ | OrientedBox box1; // creates a unit box centered at (0,0,0) with no rotation | ||
+ | OrientedBox box2(Point(1, | ||
+ | Matrix3x3 rotation = // some arbitrary 3x3 rotation matrix | ||
+ | OrientedBox box3(Point(0, | ||
+ | </ | ||
+ | |||
+ | ===== Plane ===== | ||
+ | The Plane struct represents a mathematical plane in 3D space. It is defined by a normal vector and a distance from the origin. | ||
+ | |||
+ | It has two fields: | ||
+ | - normal: a Vector3 representing the normal vector of the plane | ||
+ | - distance: a float representing the distance of the plane from the origin along the normal vector | ||
+ | |||
+ | It has two constructors: | ||
+ | - Plane(): sets the normal vector to (1, 0, 0) and calculates the distance based on the distance from the origin to the normal vector | ||
+ | - Plane(const Vector3& | ||
+ | |||
+ | It has one function: | ||
+ | - PlaneEquation(const Point& pt): takes a Point pt and returns the result of the plane equation for that point, which is the dot product of the point and the normal vector, minus the distance from the origin. | ||
+ | |||
+ | Example usage: | ||
+ | <code cpp> | ||
+ | Plane p1; // creates a plane with normal vector (1,0,0) and distance calculated from the origin | ||
+ | Plane p2(Vector3(0, | ||
+ | Point pt(1,2,3); | ||
+ | float planeEq = p1.PlaneEquation(pt); | ||
+ | </ | ||
+ | |||
+ | ===== Ray ===== | ||
+ | The Ray struct represents a ray in 3D space. It is defined by an origin point and a direction vector. | ||
+ | |||
+ | It has two fields: | ||
+ | - origin: a Point representing the starting point of the ray | ||
+ | - direction: a Vector3 representing the direction of the ray | ||
+ | |||
+ | It has three constructors: | ||
+ | - Ray(): creates a default ray with an origin of (0, 0, 0) and a direction of (0, 0, 1) | ||
+ | - Ray(const Line& line): creates a ray from a Line object, using the start of the line as the origin and the vector between the start and end points as the direction | ||
+ | - Ray(const Point& o, const Vector3& | ||
+ | |||
+ | It has one function: | ||
+ | - NormalizeDirection(): | ||
+ | |||
+ | Example usage: | ||
+ | <code cpp> | ||
+ | Ray r1; // creates a default ray with origin (0,0,0) and direction (0,0,1) | ||
+ | Line l1(Point(1, | ||
+ | Ray r2(l1); // creates a ray with origin (1,2,3) and direction (3,3,3) | ||
+ | Ray r3(Point(1, | ||
+ | r3.NormalizeDirection(); | ||
+ | </ | ||
+ | |||
+ | ===== Sphere ===== | ||
+ | The Sphere struct represents a sphere in 3D space. It is defined by an origin point and a radius. | ||
+ | |||
+ | It has two fields: | ||
+ | - origin: a Point representing the center of the sphere | ||
+ | - radius: a float representing the radius of the sphere | ||
+ | |||
+ | It has two constructors: | ||
+ | - Sphere(): creates a default sphere with an origin of (0, 0, 0) and a radius of 1.0 | ||
+ | - Sphere(const Point& o, float r): creates a sphere with the given origin point and radius | ||
+ | |||
+ | Example usage: | ||
+ | <code cpp> | ||
+ | Sphere s1; // creates a default sphere with center (0,0,0) and radius 1.0 | ||
+ | Sphere s2(Point(1, | ||
+ | </ | ||
+ | |||
+ | ===== Triangle ===== | ||
+ | The Triangle struct represents a triangle in 3D space. It is defined by three vertices. | ||
+ | |||
+ | It has one union field containing: | ||
+ | - struct fields: | ||
+ | - p1: a Vector3 representing the first vertex of the triangle | ||
+ | - p2: a Vector3 representing the second vertex of the triangle | ||
+ | - p3: a Vector3 representing the third vertex of the triangle | ||
+ | - array fields: | ||
+ | - points: an array of 3 Vector3s representing the vertices of the triangle | ||
+ | - points_f: an array of 9 floats representing the vertices of the triangle as a flat array of floats | ||
+ | |||
+ | It has two constructors: | ||
+ | - Triangle(): creates a default triangle with all vertices set to the zero vector | ||
+ | - Triangle(const Vector3& | ||
+ | |||
+ | Example usage: | ||
+ | <code cpp> | ||
+ | Triangle t1; // creates a default triangle with all vertices at (0, 0, 0) | ||
+ | Triangle t2(Vector3(1, | ||
+ | </ |