User Tools

Site Tools


3d_geometric_shapes

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
3d_geometric_shapes [2023/04/13 19:52]
max
3d_geometric_shapes [2023/04/13 19:56] (current)
max added remaining shapes
Line 80: Line 80:
 Matrix3x3 rotation = // some arbitrary 3x3 rotation matrix 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 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> </code>
3d_geometric_shapes.txt ยท Last modified: 2023/04/13 19:56 by max