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
locationGeoPointlocation of the plane
p1GeoPointspecifies the direction of the x-axis
p2GeoPointspecifies 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
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
LocationGeoPointlocation of the plane
DirectionXGeoVectordirection of the x-axis
DirectionYGeoVectordirection 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
dataIJsonReadStructthe 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
basePlanePlanethe 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
Plane(StandardPlane, double)
Creates a new plane parallel to a Plane.StandardPlane with a given offset
public Plane(Plane.StandardPlane std, double offset)
Parameters
stdPlane.StandardPlanethe standard plane
offsetdoublethe offset to the standard plane
Plane(SerializationInfo, StreamingContext)
Constructor required by deserialization
public Plane(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
XYPlane
Returns the X/Y plane.
public static readonly Plane XYPlane
Field Value
XZPlane
Returns the X/Z plane.
public static readonly Plane XZPlane
Field Value
YZPlane
Returns the Y/Z plane.
public static readonly Plane YZPlane
Field Value
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
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
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
Location
Gets or sets the location of this plane
public GeoPoint Location { get; set; }
Property Value
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
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
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
cGeoPoint2Dthe 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
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
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
pGeoPointthe 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
gGeoPointthe 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
fromHereGeoPointthe point to project
Returns
- GeoPoint
the foot of the perpendicular from
fromHereonto 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
pointsGeoPoint[]points to build the plane from
maxDistancedoublemaximum distance of the points from the plane
isLinearbooltrue, 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
PointsGeoPoint[]points to build the plane from
MaxDistancedoublemaximum distance of the points from the resulting plane, MaxValue when the points do not define a plane
isLinearbooltrue, 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
dataIJsonWriteDatathe 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
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
SourceBeamAxisthe 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
Returns
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
LinePointGeoPointpoint on the line
LineDirGeoVectordirection of the line
ipGeoPointthe 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
otherPlanethe other plane
locGeoPointa point on the intersection line: the point of the line closest to the Location of this plane
dirGeoVectordirection of the intersection line
Returns
- bool
true, if the planes intersect; false if they are parallel,
locanddirare 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
loc1GeoPointpoint on the first plane
norm1GeoVectornormal of the first plane
loc2GeoPointpoint on the second plane
norm2GeoVectornormal of the second plane
loc3GeoPointpoint on the third plane
norm3GeoVectornormal of the third plane
ipGeoPointthe 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
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
mModOpthe modification to apply
Offset(double)
Returns a plane parallel to this plane with the given offset
public Plane Offset(double dist)
Parameters
distdoublethe 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
pGeoPointthe 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
pGeoPoint[]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
vGeoVectorthe 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
dataIJsonReadDatanot 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
pGeoPointpoint 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
pGeoPoint2D2d 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
vGeoVectora 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
vGeoVector2D2d 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
pGeoPointpoint (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
vGeoVectorvector (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
pPlaneplane in global system
Returns
- Plane
plane in local system