Package geomss.geom.nurbs
Class ControlPoint
- java.lang.Object
-
- geomss.geom.nurbs.ControlPoint
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,javolution.lang.Immutable
,javolution.lang.ValueType
,javolution.xml.XMLSerializable
public class ControlPoint extends java.lang.Object implements java.lang.Cloneable, javolution.xml.XMLSerializable, javolution.lang.ValueType
A container that holds the coordinates of a NURBS control point in n-dimensional space.Modified by: Joseph A. Huwaldt
- Version:
- February 17, 2025
- Author:
- Joseph A. Huwaldt, Date: May 14, 2009
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ControlPoint
applyWeight()
Returns a new ControlPoint with the geometric point portion of this control point multiplied by the weight.ControlPoint
changeWeight(double value)
Return a new control point that is identical to this one, but with the weight changed to the specified value.java.lang.Object
clone()
Returns a copy of this ControlPoint instanceallocated
by the calling thread (possibly on the stack).ControlPoint
copy()
Returns a copy of this ControlPoint instanceallocated
by the calling thread (possibly on the stack).double
distance(ControlPoint cp)
Return the distance (in homogeneous coordinates) between this control point and another (this treats the weight simply as another dimension).ControlPoint
divide(double divisor)
Returns a new control point with this point divided by the specified divisor.boolean
equals(java.lang.Object obj)
Compares this ControlPoint against the specified object for strict equality (same values and same units).Point
getBoundsMax()
Return the coordinate point representing the maximum bounding box corner (e.g.: max X, max Y, max Z).Point
getBoundsMin()
Return the coordinate point representing the minimum bounding box corner (e.g.: min X, min Y, min Z).ControlPoint
getHomogeneous()
Return a copy of this control point with the values made homogeneous (all the geometric point values are divided by the weight).int
getPhyDimension()
Returns the number of physical dimensions of the geometry element.Point
getPoint()
Return the Point representation of this ControlPoint.javax.measure.unit.Unit<javax.measure.quantity.Length>
getUnit()
Returns the unit in which this control point is stated.double
getValue(int i)
Returns the value of the Parameter in this point as adouble
, stated in this point's unit.double
getWeight()
Return the weight associated with this control point.int
hashCode()
Returns the hash code for this parameter.boolean
isValid()
Returntrue
if this control point contains valid and finite numerical components.ControlPoint
minus(ControlPoint that)
Returns a new control point with the difference between this point with the one specified.static ControlPoint
newInstance(int dim)
Returns aControlPoint
instance of the specified dimension with zero meters for each coordinate value and zero weight.static ControlPoint
newInstance(int dim, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns aControlPoint
instance of the specified dimension and units with zero for each coordinate value and zero weight.double
normValue()
Returns the norm, magnitude, or length value of the vector from the origin to this control point geometric point (square root of the dot product of the origin-to-this-point vector and itself).ControlPoint
plus(ControlPoint that)
Returns a new control point with the sum of this point with the one specified.ControlPoint
times(double k)
Returns a new control point with the product of this point with the specified coefficient.ControlPoint
to(javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns the equivalent to this control point but stated in the specified unit.double[]
toArray()
Returns the values stored in this control point as a Java array, stated in the currentunits
with the weight tacked onto the end of the array.double[]
toArray(double[] array)
Returns the values stored in this control point, with the coordinate point stated in the currentunits
and the weight tacked onto the end, stored in the input Java array.Float64Vector
toFloat64Vector()
Returns the values stored in this control point, with the coordinate points stated in this point's unit and the weight tacked onto the end as a Float64Vector.java.lang.String
toString()
Returns the String representation of this control point that consists of the the geometry coordinate values followed by the weighting factor.javolution.text.Text
toText()
Returns the text representation of this control point that consists of the the geometry coordinate values followed by the weighting factor.static ControlPoint
valueOf(double x, double y, double w)
Returns a 2DControlPoint
instance holding the specifieddouble
values stated in meters.static ControlPoint
valueOf(double x, double y, double z, double w)
Returns a 3DControlPoint
instance holding the specifieddouble
values stated in meters.static ControlPoint
valueOf(double x, double y, double z, double w, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns a 3DControlPoint
instance holding the specifieddouble
values stated in the specified units.static ControlPoint
valueOf(double x, double y, double w, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns a 2DControlPoint
instance holding the specifieddouble
values stated in the specified units.static ControlPoint
valueOf(ControlPoint point)
Returns aControlPoint
instance containing the specified ControlPoint's data.static ControlPoint
valueOf(Point point, double w)
Returns aControlPoint
instance containing the specified Point's data.static ControlPoint
valueOf(javax.measure.unit.Unit<javax.measure.quantity.Length> unit, double[] vector)
Returns aControlPoint
instance holding the specifieddouble
values stated in the specified units.static ControlPoint
valueOf(Vector<Float64> vector, double w, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns aControlPoint
instance holding the specifiedFloat64
values plus weight stated in the specified units.static ControlPoint
valueOf(Vector<Float64> vector, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns aControlPoint
instance holding the specifiedFloat64
values stated in the specified units.
-
-
-
Method Detail
-
newInstance
public static ControlPoint newInstance(int dim)
Returns aControlPoint
instance of the specified dimension with zero meters for each coordinate value and zero weight.- Parameters:
dim
- the physical dimension of the point to create (not including the weighting factor).- Returns:
- the point having the specified dimension and zero meters for values.
-
newInstance
public static ControlPoint newInstance(int dim, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns aControlPoint
instance of the specified dimension and units with zero for each coordinate value and zero weight.- Parameters:
dim
- the physical dimension of the point to create (not including the weighting factor).unit
- the unit for the point coordinate values. May not be null.- Returns:
- the point having the specified dimension & unit and zero for values.
-
valueOf
public static ControlPoint valueOf(double x, double y, double w)
Returns a 2DControlPoint
instance holding the specifieddouble
values stated in meters.- Parameters:
x
- the x value stated in meters.y
- the y value stated in meters.w
- the weighting factor for the control point.- Returns:
- the point having the specified values.
-
valueOf
public static ControlPoint valueOf(double x, double y, double w, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns a 2DControlPoint
instance holding the specifieddouble
values stated in the specified units.- Parameters:
x
- the x value stated in the specified unit.y
- the y value stated in the specified unit.w
- the weighting factor for the control point.unit
- the unit in which the coordinates are stated. May not be null.- Returns:
- the point having the specified values.
-
valueOf
public static ControlPoint valueOf(double x, double y, double z, double w)
Returns a 3DControlPoint
instance holding the specifieddouble
values stated in meters.- Parameters:
x
- the x value stated in meters.y
- the y value stated in meters.z
- the z value stated in meters.w
- the weighting factor for the control point.- Returns:
- the point having the specified values.
-
valueOf
public static ControlPoint valueOf(double x, double y, double z, double w, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns a 3DControlPoint
instance holding the specifieddouble
values stated in the specified units.- Parameters:
x
- the x value stated in the specified unit.y
- the y value stated in the specified unit.z
- the z value stated in meters.w
- the weighting factor for the control point.unit
- the unit in which the coordinates are stated. May not be null.- Returns:
- the point having the specified values.
-
valueOf
public static ControlPoint valueOf(Vector<Float64> vector, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns aControlPoint
instance holding the specifiedFloat64
values stated in the specified units.- Parameters:
vector
- the vector of Float64 values stated with all but the last stated in the specified unit (the last is assumed to be the weight). May not be null.unit
- the unit in which the coordinates are stated. May not be null.- Returns:
- the point having the specified values.
-
valueOf
public static ControlPoint valueOf(Vector<Float64> vector, double w, javax.measure.unit.Unit<javax.measure.quantity.Length> unit)
Returns aControlPoint
instance holding the specifiedFloat64
values plus weight stated in the specified units.- Parameters:
vector
- the vector of Float64 values representing the geometric point stated in the specified unit. May not be null.w
- the weighting factor for the control point.unit
- the unit in which the coordinates are stated. May not be null.- Returns:
- the control point having the specified values.
-
valueOf
public static ControlPoint valueOf(javax.measure.unit.Unit<javax.measure.quantity.Length> unit, double[] vector)
Returns aControlPoint
instance holding the specifieddouble
values stated in the specified units.- Parameters:
unit
- the unit in which the coordinates are stated. May not be null.vector
- the vector of coordinate values with all but the last stated in the specified unit (the last is assumed to be the weight). May not be null.- Returns:
- the control point having the specified values.
-
valueOf
public static ControlPoint valueOf(Point point, double w)
Returns aControlPoint
instance containing the specified Point's data.- Parameters:
point
- the Point to be copied into a new ControlPoint. May not be null.w
- the weighting factor for the control point.- Returns:
- the point having the specified values.
-
valueOf
public static ControlPoint valueOf(ControlPoint point)
Returns aControlPoint
instance containing the specified ControlPoint's data.- Parameters:
point
- the ControlPoint to be copied into a new ControlPoint. May not be null.- Returns:
- the point having the specified values.
-
getPhyDimension
public int getPhyDimension()
Returns the number of physical dimensions of the geometry element. This implementation returns the dimensions of the point and does not count the weighting factor.- Returns:
- The physical dimensions of the control points not counting the weighting factor.
-
getValue
public double getValue(int i)
Returns the value of the Parameter in this point as adouble
, stated in this point's unit.- Parameters:
i
- the dimension index.- Returns:
- the value of the Parameter at
i
. - Throws:
java.lang.IndexOutOfBoundsException
-(i < 0) || (i > getPhyDimension() - 1)
-
getPoint
public Point getPoint()
Return the Point representation of this ControlPoint.- Returns:
- A Point representation of this control point.
-
getWeight
public double getWeight()
Return the weight associated with this control point.- Returns:
- The weighting factor associated with this control point.
-
changeWeight
public ControlPoint changeWeight(double value)
Return a new control point that is identical to this one, but with the weight changed to the specified value.- Parameters:
value
- The new weighting factor.- Returns:
- A new ControlPoint identical to this one but with the specified weight.
-
getHomogeneous
public ControlPoint getHomogeneous()
Return a copy of this control point with the values made homogeneous (all the geometric point values are divided by the weight).- Returns:
- A new ControlPoint with the values made homogeneous.
-
applyWeight
public ControlPoint applyWeight()
Returns a new ControlPoint with the geometric point portion of this control point multiplied by the weight.- Returns:
- A new ControlPoint with the geometric point multiplied by the weight.
-
plus
public ControlPoint plus(ControlPoint that)
Returns a new control point with the sum of this point with the one specified.- Parameters:
that
- the point to be added to this one. May not be null.- Returns:
- A new ControlPoint with this + that.
- Throws:
DimensionException
- if point dimensions are different.
-
minus
public ControlPoint minus(ControlPoint that)
Returns a new control point with the difference between this point with the one specified.- Parameters:
that
- the point to be subtracted from this one. May not be null.- Returns:
- A new ControlPoint with this - that.
- Throws:
DimensionException
- if point dimensions are different.
-
times
public ControlPoint times(double k)
Returns a new control point with the product of this point with the specified coefficient.- Parameters:
k
- the coefficient multiplier.- Returns:
- A new ControlPoint with this*k.
-
divide
public ControlPoint divide(double divisor)
Returns a new control point with this point divided by the specified divisor.- Parameters:
divisor
- the divisor.- Returns:
- A new ControlPoint with this / divisor.
-
normValue
public double normValue()
Returns the norm, magnitude, or length value of the vector from the origin to this control point geometric point (square root of the dot product of the origin-to-this-point vector and itself).- Returns:
- The magnitude of the vector from the origin to this control point. geometric point.
-
distance
public double distance(ControlPoint cp)
Return the distance (in homogeneous coordinates) between this control point and another (this treats the weight simply as another dimension).- Parameters:
cp
- The control point to find the homogeneous distance to. May not be null.- Returns:
- The homogeneous distance to the specified control point from this one.
-
getBoundsMin
public Point getBoundsMin()
Return the coordinate point representing the minimum bounding box corner (e.g.: min X, min Y, min Z).- Returns:
- The minimum bounding box coordinate for this geometry element.
-
getBoundsMax
public Point getBoundsMax()
Return the coordinate point representing the maximum bounding box corner (e.g.: max X, max Y, max Z).- Returns:
- The maximum bounding box coordinate for this geometry element.
-
isValid
public boolean isValid()
Returntrue
if this control point contains valid and finite numerical components. A value offalse
will be returned if any of the coordinate values are NaN or Inf (including the weight).- Returns:
- true if this control point contains valid and finite values.
-
getUnit
public javax.measure.unit.Unit<javax.measure.quantity.Length> getUnit()
Returns the unit in which this control point is stated.- Returns:
- The unit in which this control point is stated.
-
to
public ControlPoint to(javax.measure.unit.Unit<javax.measure.quantity.Length> unit) throws javax.measure.converter.ConversionException
Returns the equivalent to this control point but stated in the specified unit.- Parameters:
unit
- The length unit of the control point to be returned. May not be null.- Returns:
- An equivalent to this control point but stated in the specified unit.
- Throws:
javax.measure.converter.ConversionException
- if the the input unit is not a length unit.
-
toFloat64Vector
public Float64Vector toFloat64Vector()
Returns the values stored in this control point, with the coordinate points stated in this point's unit and the weight tacked onto the end as a Float64Vector.- Returns:
- A Float64Vector representation of this control point.
-
toArray
public double[] toArray()
Returns the values stored in this control point as a Java array, stated in the currentunits
with the weight tacked onto the end of the array.- Returns:
- A new array with the control point values copied into it with the weight at the end.
-
toArray
public double[] toArray(double[] array)
Returns the values stored in this control point, with the coordinate point stated in the currentunits
and the weight tacked onto the end, stored in the input Java array.- Parameters:
array
- An existing array that has at least as many elements as the physical dimension of this point + 1 for the weight.- Returns:
- A reference to the input array after the control point values have been copied over to it.
- See Also:
getPhyDimension()
-
copy
public ControlPoint copy()
Returns a copy of this ControlPoint instanceallocated
by the calling thread (possibly on the stack).- Specified by:
copy
in interfacejavolution.lang.ValueType
- Returns:
- an identical and independent copy of this point.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns a copy of this ControlPoint instanceallocated
by the calling thread (possibly on the stack).- Returns:
- an identical and independent copy of this point.
- Throws:
java.lang.CloneNotSupportedException
- Never thrown.
-
equals
public boolean equals(java.lang.Object obj)
Compares this ControlPoint against the specified object for strict equality (same values and same units).- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare with.- Returns:
true
if this point is identical to that point;false
otherwise.
-
hashCode
public int hashCode()
Returns the hash code for this parameter.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code value.
-
toText
public javolution.text.Text toText()
Returns the text representation of this control point that consists of the the geometry coordinate values followed by the weighting factor. For example:{{10 ft, -3 ft, 4.56 ft}, 1.0}
- Returns:
- the text representation of this geometry element.
-
toString
public java.lang.String toString()
Returns the String representation of this control point that consists of the the geometry coordinate values followed by the weighting factor. For example:{{10 ft, -3 ft, 4.56 ft}, 1.0}
- Overrides:
toString
in classjava.lang.Object
- Returns:
- the text representation of this geometry element.
-
-