Table of Contents

Struct Plane

Namespace
CADability
Assembly
CADability.dll

A simple plane as a value type. Is used e.g. as a drawing plane, an intersection plane etc. It also serves as a coordinate system (see CoordSys).

[JsonVersion(serializeAsStruct = true, version = 1)]
public struct Plane : ISerializable, IJsonSerialize
Implements
Inherited Members

Constructors

Plane(GeoPoint, GeoPoint, GeoPoint)

Creates a new plane with the given parameters. Throws a PlaneException, if the three points are colinear

public Plane(GeoPoint location, GeoPoint p1, GeoPoint p2)

Parameters

location GeoPoint

location of the plane

p1 GeoPoint

specifies the direction of the x-axis

p2 GeoPoint

specifies the direction of the y-axis, wich will be perpendicular to the x-axis

Plane(GeoPoint, GeoVector)

Creates a new plane. The parameter data is under-determined for the plane, so the x-axis and y-axis will be determined arbitrarily

public Plane(GeoPoint location, GeoVector normal)

Parameters

location GeoPoint

location of the plane

normal GeoVector

normal vector of the plane

Plane(GeoPoint, GeoVector, GeoVector)

Creates a new plane with the given parameters. Throws a PlaneException, if DirectionX and DirectionY have the same direction.

public Plane(GeoPoint Location, GeoVector DirectionX, GeoVector DirectionY)

Parameters

Location GeoPoint

location of the plane

DirectionX GeoVector

direction of the x-axis

DirectionY GeoVector

direction of the y-axis, will be adapted if not perpendicular to the x-axis

Plane(IJsonReadStruct)

Constructor required by JSON deserialization. Reads the coordinate system written by GetObjectData(IJsonWriteData).

public Plane(IJsonReadStruct data)

Parameters

data IJsonReadStruct

the stored values

Plane(Plane)

Creates a copy of basePlane. Since Plane is a value type an assignment does the same; the constructor is used where a copy is subsequently modified, e.g. by the * operator of ModOp.

public Plane(Plane basePlane)

Parameters

basePlane Plane

the plane to copy

Plane(Plane, double)

Creates a plane parallel to basePlane, shifted by offset along the normal of the base plane. The direction vectors are those of the base plane. Same as Offset(double).

public Plane(Plane basePlane, double offset)

Parameters

basePlane Plane

the plane to shift

offset double

signed distance along the normal of basePlane

Plane(StandardPlane, double)

Creates a new plane parallel to a Plane.StandardPlane with a given offset

public Plane(Plane.StandardPlane std, double offset)

Parameters

std Plane.StandardPlane

the standard plane

offset double

the offset to the standard plane

Plane(SerializationInfo, StreamingContext)

Constructor required by deserialization

public Plane(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

SerializationInfo

context StreamingContext

StreamingContext

Fields

XYPlane

Returns the X/Y plane.

public static readonly Plane XYPlane

Field Value

Plane

XZPlane

Returns the X/Z plane.

public static readonly Plane XZPlane

Field Value

Plane

YZPlane

Returns the Y/Z plane.

public static readonly Plane YZPlane

Field Value

Plane

Properties

CoordSys

Returns the coordinate system corresponding to this plane. The z-axis of the coordinate system is the normal vector of this plane (always right handed)

public CoordSys CoordSys { get; }

Property Value

CoordSys

DirectionX

Gets or sets the direction of the x-axis of this plane. Setting the x-axis results in a reculculation of the y-axis to make the axis perpendicular.

public GeoVector DirectionX { get; set; }

Property Value

GeoVector

DirectionY

Gets or sets the direction of the y-axis of this plane. Setting the y-axis results in a reculculation of the x-axis to make the axis perpendicular.

public GeoVector DirectionY { get; set; }

Property Value

GeoVector

Location

Gets or sets the location of this plane

public GeoPoint Location { get; set; }

Property Value

GeoPoint

ModOpToGlobal

The modification that transforms from the coordinate system of this plane into the global system: the origin goes to Location, the x-, y- and z-axis to DirectionX, DirectionY and Normal. It does the same as ToGlobal(GeoPoint), but can be applied to whole objects.

public ModOp ModOpToGlobal { get; }

Property Value

ModOp

Normal

Gets or sets the normal vector of this plane. Setting the normal vector results in a recalculation of the x-axis and y-axis of this plane

public GeoVector Normal { get; set; }

Property Value

GeoVector

Methods

Align(GeoPoint2D)

Moves the origin of the coordinate system of this plane to the point c, given in the current 2d coordinates of the plane. The plane itself and its direction vectors do not change, only Location.

public void Align(GeoPoint2D c)

Parameters

c GeoPoint2D

the new origin in the 2d coordinate system of the plane

Align(Plane, bool)

Aligns the DirectionX and DirectionY vectors of this plane so that the projection of DirectionX of AlignTo and DircetionX of this plane are parallel. If the two planes are parallel, the DirectionX and DirectionY of both planes will also be parallel. The plane will not be changed. The Location of this plane will be changed to a point closest to the location of AlignTo, if relocate is true, otherwise the location remains unchanged.

public void Align(Plane alignTo, bool relocate)

Parameters

alignTo Plane

Plane to align to

relocate bool

relocate this plane

Align(Plane, bool, bool)

Aligns the DirectionX and DirectionY vectors of this plane so that the projection of DirectionX of AlignTo and DircetionX of this plane are parallel. If the two planes are parallel, the DirectionX and DirectionY of both planes will also be parallel. The plane will not be changed. The Location of this plane will be changed to a point closest to the location of AlignTo, if relocate is true, otherwise the location remains unchanged. If flip is true there is an additional check whether the angle between the two normal vectors is less than 90°. If not, the y-axis is reversed and the angle between the two normal vectors will be less than 90°

public void Align(Plane alignTo, bool relocate, bool flip)

Parameters

alignTo Plane

Plane to align to

relocate bool

relocate this plane

flip bool

Distance(GeoPoint)

Returns the signed distance of the point from the plane. The direction of the normal vector of the plane determins the sign of the result.

public double Distance(GeoPoint p)

Parameters

p GeoPoint

the point

Returns

double

the distance

Elem(GeoPoint)

Checks whether the point lies on this plane, i.e. its distance from the plane is less than eps.

public bool Elem(GeoPoint g)

Parameters

g GeoPoint

the point to test

Returns

bool

true, if the point is on the plane

FootPoint(GeoPoint)

Returns the perpendicular projection of the given point onto this plane as a 3d point, in contrast to Project(GeoPoint), which returns it in the 2d coordinate system of the plane.

public GeoPoint FootPoint(GeoPoint fromHere)

Parameters

fromHere GeoPoint

the point to project

Returns

GeoPoint

the foot of the perpendicular from fromHere onto this plane

FromPoints(GeoPoint[], out double, out bool)

Finds a plane that best fits through the given points. Calculates also the maximum distance of the points from that plane. If maxDistance is 0.0 or small, the points are coplanar. The normal of the plane points to positive z. If it is (almost) perpendicular to the z-axis, it points to positive y, and if it is (almost) the x-axis, it points to positive x. Points in the XY plane yield a plane with the normal +Z.

public static Plane FromPoints(GeoPoint[] points, out double maxDistance, out bool isLinear)

Parameters

points GeoPoint[]

points to build the plane from

maxDistance double

maximum distance of the points from the plane

isLinear bool

true, if the points do not define a plane because there are fewer than three distinct points or they all lie (almost) on a line; the XY plane is returned in that case

Returns

Plane

the plane

FromPointsOld(GeoPoint[], out double, out bool)

Older implementation of FromPoints(GeoPoint[], out double, out bool): fits a plane through the given points by minimizing the residuals along the dominant axis of the covariance of the points, which is not always the best fitting plane. No longer used internally, kept for compatibility; prefer FromPoints(GeoPoint[], out double, out bool).

public static Plane FromPointsOld(GeoPoint[] Points, out double MaxDistance, out bool isLinear)

Parameters

Points GeoPoint[]

points to build the plane from

MaxDistance double

maximum distance of the points from the resulting plane, MaxValue when the points do not define a plane

isLinear bool

true, if the points do not define a plane: fewer than three points, all points coincide or they lie on a line. The result is then the XYPlane

Returns

Plane

the fitted plane

GetObjectData(IJsonWriteData)

Implements GetObjectData(IJsonWriteData): writes the coordinate system of the plane as a list of values.

public void GetObjectData(IJsonWriteData data)

Parameters

data IJsonWriteData

the JSON writer

GetProjection()

Returns a projection that projects (perpendiccular) from global space to this plane

public Projection GetProjection()

Returns

Projection

the projection

Interfere(GeoPoint, GeoPoint)

Intersects the line segment from sp to ep with this plane.

public GeoPoint[] Interfere(GeoPoint sp, GeoPoint ep)

Parameters

sp GeoPoint

start point of the segment

ep GeoPoint

end point of the segment

Returns

GeoPoint[]

an array with the single intersection point if the segment crosses the plane between its end points, otherwise an empty array

Intersect(Axis)

Intersects the given axis (infinite line) with this plane and returns the intersection point in the 2d coordinate system of the plane. Throws a PlaneException when the axis is parallel to the plane.

public GeoPoint2D Intersect(Axis SourceBeam)

Parameters

SourceBeam Axis

the axis to intersect

Returns

GeoPoint2D

the intersection point in plane coordinates

Intersect(GeoPoint, GeoVector)

Returns the intersection plane of the line given by the parameters with this plane.

public GeoPoint Intersect(GeoPoint LinePoint, GeoVector LineDir)

Parameters

LinePoint GeoPoint

point on the line

LineDir GeoVector

direction of the line

Returns

GeoPoint

Intersect(GeoPoint, GeoVector, out GeoPoint)

Intersects the infinite line given by LinePoint and LineDir with this plane. Unlike Intersect(GeoPoint, GeoVector) this overload does not throw when the line is (almost) parallel to the plane but returns false.

public bool Intersect(GeoPoint LinePoint, GeoVector LineDir, out GeoPoint ip)

Parameters

LinePoint GeoPoint

point on the line

LineDir GeoVector

direction of the line

ip GeoPoint

the intersection point, Origin if there is none

Returns

bool

true, if the line intersects the plane

Intersect(Plane, out GeoPoint, out GeoVector)

Intersects this plane with another plane. The intersection line is returned as a point on it and its direction, which is the cross product of the two normals (not normalized).

public bool Intersect(Plane other, out GeoPoint loc, out GeoVector dir)

Parameters

other Plane

the other plane

loc GeoPoint

a point on the intersection line: the point of the line closest to the Location of this plane

dir GeoVector

direction of the intersection line

Returns

bool

true, if the planes intersect; false if they are parallel, loc and dir are then the origin and the x-axis

Intersect3Planes(GeoPoint, GeoVector, GeoPoint, GeoVector, GeoPoint, GeoVector, out GeoPoint)

Computes the common point of three planes, each given by a point and its normal vector, by solving the three linear equations norm_i * x = norm_i * loc_i.

public static bool Intersect3Planes(GeoPoint loc1, GeoVector norm1, GeoPoint loc2, GeoVector norm2, GeoPoint loc3, GeoVector norm3, out GeoPoint ip)

Parameters

loc1 GeoPoint

point on the first plane

norm1 GeoVector

normal of the first plane

loc2 GeoPoint

point on the second plane

norm2 GeoVector

normal of the second plane

loc3 GeoPoint

point on the third plane

norm3 GeoVector

normal of the third plane

ip GeoPoint

the intersection point, Origin if there is none

Returns

bool

true, if the planes meet in a single point; false if the normals are linearly dependent (two of the planes are parallel or all three share a common line)

IsValid()

An uninitialized plane is invalid, because its normal vector is (0,0,0).

public bool IsValid()

Returns

bool

Modify(ModOp)

Transforms this plane by the given modification: location, x-direction and normal are transformed, the directions are normalized and DirectionY is recomputed so that the coordinate system stays orthonormal and right handed. A scaling or shearing modification therefore does not preserve the 2d coordinates of points on the plane.

public void Modify(ModOp m)

Parameters

m ModOp

the modification to apply

Offset(double)

Returns a plane parallel to this plane with the given offset

public Plane Offset(double dist)

Parameters

dist double

the offset

Returns

Plane

the parallel plane

Project(GeoPoint)

Projects the given point (perpendicular) onto this plane and returns the two-dimensional point as expressed in the coordinate system of this plane.

public GeoPoint2D Project(GeoPoint p)

Parameters

p GeoPoint

the point

Returns

GeoPoint2D

the point in the coordinate system of this plane

Project(GeoPoint[])

Projects the given point (perpendicular) onto this plane and returns the two-dimensional point as expressed in the coordinate system of this plane.

public GeoPoint2D[] Project(GeoPoint[] p)

Parameters

p GeoPoint[]

the point

Returns

GeoPoint2D[]

the point in the coordinate system of this plane

Project(GeoVector)

Projects the given vector (perpendicular) onto this plane and returns the two-dimensional vector as expressed in the coordinate system of this plane.

public GeoVector2D Project(GeoVector v)

Parameters

v GeoVector

the vector

Returns

GeoVector2D

the vector in the coordinate system of this plane

Reverse()

Flips this plane: Normal and DirectionX are reversed, DirectionY and Location stay, so the coordinate system remains right handed. The signed Distance(GeoPoint) of all points changes its sign.

public void Reverse()

SetObjectData(IJsonReadData)

Implements SetObjectData(IJsonReadData). Does nothing, because a Plane is serialized as a struct and read back by the Plane(IJsonReadStruct) constructor.

public void SetObjectData(IJsonReadData data)

Parameters

data IJsonReadData

not used

ToGlobal(GeoPoint)

Inverse to the appropriate ToLocal(GeoPoint) method. The given point is assumed in the coordinate ststem of this plane. Returns the point in the global coordinate system.

public GeoPoint ToGlobal(GeoPoint p)

Parameters

p GeoPoint

point in the plane coordinate system

Returns

GeoPoint

point in the global coordinate system

ToGlobal(GeoPoint2D)

Inverse to the appropriate Project(GeoPoint) method. Returns the point in the global coordinate system

public GeoPoint ToGlobal(GeoPoint2D p)

Parameters

p GeoPoint2D

2d point in the local system of this plane

Returns

GeoPoint

3d point in the global coordinate system

ToGlobal(GeoVector)

Returns the 3D GeoVector corresponding to the given GeoVector in the coordinate system of the plane.

public GeoVector ToGlobal(GeoVector v)

Parameters

v GeoVector

a vector in the coordinate system of the plane

Returns

GeoVector

a 3D vector in the global coordinate system

ToGlobal(GeoVector2D)

Inverse to the appropriate Project(GeoVector) method. Returns the vector in the global coordinate system

public GeoVector ToGlobal(GeoVector2D v)

Parameters

v GeoVector2D

2d vector in the coordinate system of the plane

Returns

GeoVector

3d vector in the global coordinate system

ToLocal(GeoPoint)

Returns the point as expressed in the coordinate system of this plane

public GeoPoint ToLocal(GeoPoint p)

Parameters

p GeoPoint

point (in the global system)

Returns

GeoPoint

point in the local system of this plane

ToLocal(GeoVector)

Returns the vector as expressed in the coordinate system of this plane

public GeoVector ToLocal(GeoVector v)

Parameters

v GeoVector

vector (in the global system)

Returns

GeoVector

vector in the local system of this plane

ToLocal(Plane)

Returns the plane given in parameter p expressed in the coordinate system of this plane

public Plane ToLocal(Plane p)

Parameters

p Plane

plane in global system

Returns

Plane

plane in local system