User Tools

Site Tools


3d_geometric_shapes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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,2,3), Point(4,5,6)); // creates a line with start at (1,2,3) and end at (4,5,6)
 +float length = Line::Length(line2); // computes the length of line2 using the precise Magnitude() method
 +float lengthFast = Line::LengthFast(line2); // computes an approximation of the length of line2 using the faster MagnitudeFast() method
 +</code>
 +
 +
 +===== 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: a Matrix3x3 representing the rotation of the box in 3D space
 +
 +It has three constructors:
 +  - OrientedBox(): sets position to (0,0,0), size to (1,1,1), and orientation to the identity matrix (no rotation)
 +  - OrientedBox(const Point& p, const Vector3& s): sets the position to the given point p, the size to the given vector s, and orientation to the identity matrix (no rotation)
 +  - OrientedBox(const Point& p, const Vector3& s, const Matrix3x3& o): sets the position to the given point p, the size to the given vector s, and orientation to the given matrix o (for arbitrary rotation)
 +
 +Example usage:
 +<code cpp>
 +OrientedBox box1; // creates a unit box centered at (0,0,0) with no rotation
 +OrientedBox box2(Point(1,2,3), Vector3(2,3,4)); // creates a box with center at (1,2,3), size (2,3,4), and no rotation
 +Matrix3x3 rotation = // some arbitrary 3x3 rotation matrix
 +OrientedBox box3(Point(0,0,0), Vector3(1,1,1), rotation); // creates a unit box at the origin, with rotation specified by the given matrix
 +</code>
 +
 +===== 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& n, float d): sets the normal vector to the given vector n and the distance to the given float d
 +
 +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,1,0), 5); // creates a plane with normal vector (0,1,0) and distance 5
 +Point pt(1,2,3);
 +float planeEq = p1.PlaneEquation(pt); // calculates the result of the plane equation for point pt on plane p1
 +</code>
 +
 +===== 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& d): creates a ray with the given origin point and direction vector. The direction vector is automatically normalized using the NormalizeDirection() function.
 +
 +It has one function:
 +  - NormalizeDirection(): normalizes the direction vector of the ray.
 +
 +Example usage:
 +<code cpp>
 +Ray r1; // creates a default ray with origin (0,0,0) and direction (0,0,1)
 +Line l1(Point(1,2,3), Point(4,5,6));
 +Ray r2(l1); // creates a ray with origin (1,2,3) and direction (3,3,3)
 +Ray r3(Point(1,2,3), Vector3(4,5,6)); // creates a ray with origin (1,2,3) and direction (0.45584, 0.5698, 0.68276)
 +r3.NormalizeDirection(); // normalizes the direction vector of r3
 +</code>
 +
 +===== 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,2,3), 4.0f); // creates a sphere with center (1,2,3) and radius 4.0
 +</code>
 +
 +===== 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& p1, const Vector3& p2, const Vector3& p3): creates a triangle with the given vertices
 +
 +Example usage:
 +<code cpp>
 +Triangle t1; // creates a default triangle with all vertices at (0, 0, 0)
 +Triangle t2(Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9)); // creates a triangle with vertices (1, 2, 3), (4, 5, 6), and (7, 8, 9)
 +</code>
3d_geometric_shapes.1681415194.txt.gz ยท Last modified: 2023/04/13 19:46 by max