Plane
A plane in Hessian normal form.
Plane.swift:14struct Plane
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.
Citizens in SwiftGodot
Conformances
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Equatable
A type that can be compared for value equality.
protocol Escapable
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol SelfVariantRepresentable
Structs and scalar types use their own layout for storage.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
init(
) Constructs a default-initialized
Plane
with all components set to0
.init(a: Float, b: Float, c: Float, d: Float
) Creates a plane from the four parameters. The three components of the resulting plane’s
normal
area
,b
andc
, and the plane has a distance ofd
from the origin.init(from: Plane
) init(normal: Vector3
) Creates a plane from the normal vector. The plane will intersect the origin.
init(normal: Vector3, d: Float
) Creates a plane from the normal vector and the plane’s distance from the origin.
init(normal: Vector3, point: Vector3
) Creates a plane from the normal vector and a point on the plane.
init(point1: Vector3, point2: Vector3, point3: Vector3
) Creates a plane from the three points, given in clockwise order.
static var godotType: Variant.GType
static let planeXy: Plane
A plane that extends in the X and Y axes (normal vector points +Z).
static let planeXz: Plane
A plane that extends in the X and Z axes (normal vector points +Y).
static let planeYz: Plane
A plane that extends in the Y and Z axes (normal vector points +X).
static func != (lhs: Plane, rhs: Plane
) -> Bool Returns
true
if the planes are not equal.static func * (lhs: Plane, rhs: Transform3D
) -> Plane Inversely transforms (multiplies) the
Plane
by the givenTransform3D
transformation matrix.static func - (p: `Self`
) -> Plane Returns the negative value of the Plane. This is the same as writing Plane(-p.normal, -p.d). This operation flips the direction of the normal vector and also flips the distance value, resulting in a Plane that is in the same place, but facing the opposite direction.
static func == (lhs: Plane, rhs: Plane
) -> Bool Returns
true
if the planes are exactly equal.
Instance members
var d: Float
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 asabs(d) / normal.length()
(ifnormal
has zero length then thisPlane
does not represent a valid plane).var normal: Vector3
The normal of the plane, typically a unit vector. Shouldn’t be a zero vector as
Plane
with suchnormal
does not represent a valid plane.func distanceTo(point: Vector3
) -> Double 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 getCenter(
) -> Vector3 Returns the center of the plane.
func hasPoint(Vector3, tolerance: Double
) -> Bool Returns
true
ifpoint
is inside the plane. Comparison uses a custom minimumtolerance
threshold.func intersect3(b: Plane, c: Plane
) -> Variant Returns the intersection point of the three planes
b
,c
and this plane. If no intersection is found,null
is returned.func intersectsRay(from: Vector3, dir: Vector3
) -> Variant Returns the intersection point of a ray consisting of the position
from
and the direction normaldir
with this plane. If no intersection is found,null
is returned.func intersectsSegment(from: Vector3, to: Vector3
) -> Variant Returns the intersection point of a segment from position
from
to positionto
with this plane. If no intersection is found,null
is returned.func isEqualApprox(toPlane: Plane
) -> Bool Returns
true
if this plane andtoPlane
are approximately equal, by running@GlobalScope.is_equal_approx
on each component.func isFinite(
) -> Bool Returns
true
if this plane is finite, by calling@GlobalScope.is_finite
on each component.func isPointOver(point: Vector3
) -> Bool Returns
true
ifpoint
is located above the plane.func normalized(
) -> Plane Returns a copy of the plane, with normalized
normal
(so it’s a unit vector). ReturnsPlane(0, 0, 0, 0)
ifnormal
can’t be normalized (it has zero length).func project(point: Vector3
) -> Vector3 Returns the orthogonal projection of
point
into a point in the plane.
Type features
init?(Variant
) static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant.
static func makeOrUnwrap(Variant
) -> Self? Unwraps an object from a variant. This is useful when you want one method to call that will return the unwrapped Variant, regardless of whether it is a SwiftGodot.Object or not.
static func != (lhs: Self, rhs: Self
) -> Bool Returns a Boolean value indicating whether two values are not equal.