Plane

package
v0.0.0-...-08a4b47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package Plane provides a plane in Hessian normal form.

Index

Constants

This section is empty.

Variables

View Source
var (
	YZ = NormalD{Normal: Vector3.XYZ{1, 0, 0}} // A plane that extends in the Y and Z axes (normal vector points +X).
	XZ = NormalD{Normal: Vector3.XYZ{0, 1, 0}} // A plane that extends in the X and Z axes (normal vector points +Y).
	XY = NormalD{Normal: Vector3.XYZ{0, 0, 1}} // A plane that extends in the X and Y axes (normal vector points +Z).
)

Functions

func Center

func Center(p NormalD) Vector3.XYZ

GetCenter returns the center of the plane.

func DistanceToPoint

func DistanceToPoint(point Vector3.XYZ, p NormalD) Float.X

DistanceToPoint returns the shortest distance from the plane to the position point. If the point is above the plane, the distance will be positive. If below, the distance will be negative.

func HasPoint

func HasPoint(point Vector3.XYZ, p NormalD) bool

HasPoint returns true if point is inside the plane. Comparison uses a custom minimum tolerance threshold.

func Intersect3

func Intersect3(a, b, c NormalD) (Vector3.XYZ, bool)

Intersect3 returns the intersection point of the three planes b, c and this plane. If no intersection is found, false is returned.

func IntersectsRay

func IntersectsRay(p NormalD, from, dir Vector3.XYZ) (Vector3.XYZ, bool)

IntersectsRay returns the intersection point of a ray consisting of the position from and the direction normal dir with this plane. If no intersection is found, false is returned.

func IntersectsSegment

func IntersectsSegment(p NormalD, from, to Vector3.XYZ) (Vector3.XYZ, bool)

IntersectsSegment returns the intersection point of a segment from position from to position to with this plane. If no intersection is found, false is returned.

func IsApproximatelyEqual

func IsApproximatelyEqual(p, other NormalD) bool

IsApproximatelyEqual returns true if this plane and other are approximately equal, by running IsApproximatelyEqual on each component.

func IsFinite

func IsFinite(p NormalD) bool

IsFinite returns true if this plane is finite, by calling IsFinite on each component.

func IsPointOver

func IsPointOver(p NormalD, point Vector3.XYZ) bool

IsPointOver returns true if point is located above the plane.

func Project

func Project(point Vector3.XYZ, p NormalD) Vector3.XYZ

Project returns the orthogonal projection of point into a point in the plane.

Types

type NormalD

type NormalD = struct {
	// Normal of the plane, typically a unit vector. Shouldn't be a zero vector as
	// Plane with such normal does not represent a valid plane.
	//
	// In the scalar equation of the plane ax + by + cz = d, this is the
	// vector (a, b, c), where d is the d property.
	Normal Vector3.XYZ

	// D is the distance from the origin to the plane, expressed in terms of normal
	// (according to its direction and magnitude). Actual absolute distance from the
	// origin to the plane can be calculated as Abs(d) / normal.Length() (if normal
	// has zero length then this Plane does not represent a valid plane).
	//
	// In the scalar equation of the plane ax + by + cz = d, this is d, while the (a, b, c) coordinates are represented by the
	// normal property.
	D Float.X
}

NormalD represents a normalized plane equation. normal is the normal of the plane (a, b, c normalized), and d is the distance from the origin to the plane (in the direction of "normal"). "Over" or "Above" the plane is considered the side of the plane towards where the normal is pointing.

func New

func New[X Float.Any | Int.Any](a, b, c, d X) NormalD

New creates a plane from the four parameters. The three components of the resulting plane's normal are a, b and c, and the plane has a distance of d from the origin.

func NormalPoint

func NormalPoint(normal, point Vector3.XYZ) NormalD

NormalPoint creates a plane from the normal vector and a point on the plane.

The normal of the plane must be a unit vector.

func Normalized

func Normalized(p NormalD) NormalD

Normalized returns a copy of the plane, with normalized normal (so it's a unit vector). Returns a zero value if normal can't be normalized (it has zero length).

func Points

func Points(a, b, c Vector3.XYZ) NormalD

Points creates a plane from the three points, given in clockwise order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL