interval.c File Reference

Detailed Description

Implementation of the functions operating on Tinterval.

See Also
Tinterval, interval.h.

Definition in file interval.c.

Functions

double NormalizeAngle (double a)
 Normalizes a angular value so that it is included in [0,2Pi]. More...
 
void NewInterval (double lower, double upper, Tinterval *i)
 Constructor. More...
 
void CopyInterval (Tinterval *i_dst, Tinterval *i_org)
 Copy constructor. More...
 
boolean CmpIntervals (Tinterval *i1, Tinterval *i2)
 Compares two intervals. More...
 
double LowerLimit (Tinterval *i)
 Gets the lower limit. More...
 
double UpperLimit (Tinterval *i)
 Gets the uppser limit. More...
 
double IntervalSize (Tinterval *i)
 Gets the uppser limit. More...
 
double DistanceToInterval (double p, Tinterval *i)
 Distance to an interval. More...
 
double IntervalCenter (Tinterval *i)
 Gets the interval center. More...
 
double PointInInterval (double r, Tinterval *i)
 Gets a point inside the interval. More...
 
void SetLowerLimit (double v, Tinterval *i)
 Sets a new lower limit. More...
 
void SetUpperLimit (double v, Tinterval *i)
 Sets a new upper limit. More...
 
void EnlargeInterval (double lo, double uo, Tinterval *i)
 Symmetrically increases the size of an interval. More...
 
void ExpandInterval (double v, Tinterval *i)
 Changes the interval limits to include a given point. More...
 
void UpdateLowerLimit (double v, Tinterval *i)
 Updates the lower limit. More...
 
void UpdateUpperLimit (double v, Tinterval *i)
 Updates the upper limit. More...
 
boolean IntervalInclusion (Tinterval *i1, Tinterval *i2)
 Checks is a given interval is fully included into another interval. More...
 
boolean Intersect (Tinterval *i1, Tinterval *i2)
 Checks is a two intervals intersect. More...
 
boolean Intersection (Tinterval *i1, Tinterval *i2, Tinterval *i_out)
 Computes the intersection of two intervals. More...
 
boolean Union (Tinterval *i1, Tinterval *i2, Tinterval *i_out)
 Computes the union of two intervals. More...
 
boolean EmptyInterval (Tinterval *i)
 Checks if a given interval is empty. More...
 
boolean IsInside (double p, double tol, Tinterval *i)
 Checks if a value is inside an interval. More...
 
void IntervalScale (Tinterval *i1, double e, Tinterval *i_out)
 Scales an interval. More...
 
void IntervalProduct (Tinterval *i1, Tinterval *i2, Tinterval *i_out)
 Product of two intervals. More...
 
void IntervalAdd (Tinterval *i1, Tinterval *i2, Tinterval *i_out)
 Addition of two intervals. More...
 
void IntervalSubstract (Tinterval *i1, Tinterval *i2, Tinterval *i_out)
 Substraction of two intervals. More...
 
void IntervalInvert (Tinterval *i, Tinterval *i_out)
 Change of sign of a given interval. More...
 
void IntervalExp (Tinterval *i, Tinterval *i_out)
 Exponentional of an interval. More...
 
void IntervalPow (Tinterval *i, unsigned int p, Tinterval *i_out)
 Power of a given interval by a integer power factor. More...
 
boolean IntervalSqrt (Tinterval *i, Tinterval *i_out)
 Interval square root. More...
 
void IntervalDivision (Tinterval *i1, Tinterval *i2, Tinterval *i_out)
 Interval division. More...
 
void IntervalOffset (Tinterval *i, double offset, Tinterval *i_out)
 Interval offset. More...
 
void IntervalSine (Tinterval *i, Tinterval *i_out)
 Interval sine. More...
 
void IntervalCosine (Tinterval *i, Tinterval *i_out)
 Interval cosine. More...
 
void IntervalTangent (Tinterval *i, Tinterval *i_out)
 Interval tangent. More...
 
void IntervalSecant2 (Tinterval *i, Tinterval *i_out)
 Interval squared secant. More...
 
void IntervalSecant2Tangent (Tinterval *i, Tinterval *i_out)
 Interval squared secant per tangent. More...
 
void IntervalAtan2 (Tinterval *is, Tinterval *ic, Tinterval *i_out)
 Interval atan2. More...
 
void PrintSymbolInterval (FILE *f, Tinterval *i)
 Prints an angular interval. More...
 
void PrintInterval (FILE *f, Tinterval *i)
 Prints an interval. More...
 
void DeleteInterval (Tinterval *i)
 Destructor. More...
 

Function Documentation

double NormalizeAngle ( double  a)

Normalizes a angular value so that it is included in [0,2Pi].

Parameters
aThe input angular value.
Returns
The normalized angular value.

Definition at line 31 of file interval.c.

References M_2PI, and M_PI.

Referenced by IntervalCosine(), IntervalSecant2Tangent(), IntervalSine(), and IntervalTangent().

void NewInterval ( double  lower,
double  upper,
Tinterval i 
)

Defines a new interval with the given limits.

Parameters
lowerThe lower limit for the new interval.
upperThe upper limit for the new interval.
iThe interval to define.

Definition at line 47 of file interval.c.

References INF_CUT, Tinterval::lower_limit, and Tinterval::upper_limit.

Referenced by AddJacobianEquationsInt(), AddMargin2Box(), AdjustBioWorldGeometry(), BoxSaddleClipping(), BoxSphereClipping(), Buffer2Box(), CleanInfEquation(), ComputeBoundingBox(), ComputeBoundingBox3d(), CropEquation(), CropLinearConstraint(), CuikNewtonInBox(), DefinePolytope(), ErrorDueToVariable(), EvaluateEquationInt(), EvaluateLinearConstraintInt(), EvaluateMonomialInt(), EvaluateVarSetInt(), GenerateEquationsFromBranch(), GenerateJointEquations(), GenerateJointRangeEquations(), GenerateJointRangeSingularityEquations(), GenerateLinkRotFLinks(), GenerateLinkRotLinks(), GenerateLinkRotQLinks(), GenerateWorldSingularityEquations(), GetEquationBounds(), GetFirstOrderApproximationToEquation(), GetJointRangeN(), GetSCpSystem(), IncrementalSampleCuikSystemInBox(), InitBox(), InitBoxFromPoint(), InitJoint(), IntervalCosine(), IntervalSecant2(), IntervalSecant2Tangent(), IntervalSine(), IntervalTangent(), IntervalVectDotProduct(), IntervalVectFromVector(), LoadLinearConstraint(), main(), NewCP(), NewInPatchJoint(), NewSphericalJoint(), NewVariable(), RandomPointInPolytope(), ReadBox(), RectangleCircleClipping(), RectangleParabolaClipping(), RegenerateSolution(), ResetLinearConstraint(), SampleCuikSystemInBox(), SegmentCircleIntersection(), SegmentSphereIntersection(), SetEquationInfo(), SimplexAddNewConstraint(), SimplexExpandBounds(), SimplexGetColBounds(), SimplexGetOptimalValue(), SimplexGetRowBounds(), SimplifyLinearConstraint(), and SplitBox().

boolean CmpIntervals ( Tinterval i1,
Tinterval i2 
)

Compares two intervals.

Parameters
i1The first interval.
i2The second interval.
Returns
TRUE if the two given intervals are the same.

Definition at line 70 of file interval.c.

References Tinterval::lower_limit, and Tinterval::upper_limit.

double DistanceToInterval ( double  p,
Tinterval i 
)

Distance of a point to an interval. This is zero for pointsin the interval.

Parameters
pThe query point.
iThe query interval.
Returns
The distance between the point and the interval.

Definition at line 112 of file interval.c.

References Tinterval::lower_limit, and Tinterval::upper_limit.

Referenced by SquaredDistancePointToBox().

double PointInInterval ( double  r,
Tinterval i 
)

Computes a point inside the interval by linear interpolation between the extremes.

If the interval is [-INF,INF] the output is 0, irrespectively of r.

If one of the extremes of the interval is +/-INF, the returned point is one plus/less than the other extreme of the interval.

Parameters
rThe interpoltion factor (must be in [0,1], otherwise the given value is cropped to this range).
iThe interval.
Returns
The point in the interval.

Definition at line 164 of file interval.c.

References IS_INF, Tinterval::lower_limit, and Tinterval::upper_limit.

Referenced by SplitBox().

void SetLowerLimit ( double  c,
Tinterval i 
)

Changes the lower limit for an interval.

Parameters
cThe new lower limit.
iThe interval.

Definition at line 196 of file interval.c.

References INF_CUT, and Tinterval::lower_limit.

void SetUpperLimit ( double  c,
Tinterval i 
)

Changes the upper limit for an interval.

Parameters
cThe new lower limit.
iThe interval.

Definition at line 201 of file interval.c.

References INF_CUT, and Tinterval::upper_limit.

void EnlargeInterval ( double  lo,
double  uo,
Tinterval i 
)

Modifies an interval adding offsets to its lower/upper limit.

Note that after this operation the interval might become empty if you use the wrong offsets. Use at your own risk.

Parameters
loValue to add to the lower limit.
uoValue to add to the upper limit.
iThe interval to enlarge.

Definition at line 206 of file interval.c.

References INF_CUT, IS_INF, IS_NOT_INF, Tinterval::lower_limit, ROUNDDOWN, ROUNDNEAR, ROUNDUP, and Tinterval::upper_limit.

Referenced by EnlargeBox().

void ExpandInterval ( double  v,
Tinterval i 
)

Changes the interval limits to include a given point..

Parameters
vThe point to be included in the interval.
iThe interval.

Definition at line 236 of file interval.c.

References INF_CUT, Tinterval::lower_limit, and Tinterval::upper_limit.

Referenced by ExpandBox().

void UpdateLowerLimit ( double  c,
Tinterval i 
)

Changes the lower limit for an interval only in the new value is upper than the current lower limit.

Parameters
cThe temptative new lower limit.
iThe interval.

Definition at line 247 of file interval.c.

References INF_CUT, and Tinterval::lower_limit.

Referenced by ReduceRange().

void UpdateUpperLimit ( double  c,
Tinterval i 
)

Changes the upper limit for an interval only in the new value is lower than the current upper limit.

Parameters
cThe new temptative upper limit.
iThe interval.

Definition at line 253 of file interval.c.

References INF_CUT, and Tinterval::upper_limit.

Referenced by ReduceRange().

boolean IntervalInclusion ( Tinterval i1,
Tinterval i2 
)

Checks is a given interval is fully included into another interval.

Parameters
i1The interval to be included.
i2The inclusion interval.
Returns
TRUE if i1 is fully included in i2.

Definition at line 262 of file interval.c.

References Tinterval::lower_limit, and Tinterval::upper_limit.

Referenced by BoxInclusion().

boolean Intersect ( Tinterval i1,
Tinterval i2 
)

Checks two given intervals have a non-empty intersection.

Parameters
i1The first interval.
i2The second interval.
Returns
TRUE if i1 and i2 intersect.

Definition at line 272 of file interval.c.

References Intersection().

Referenced by CropEquation().

boolean Intersection ( Tinterval i1,
Tinterval i2,
Tinterval i_out 
)

Computes the intersection of two intervals.

Parameters
i1The first interval.
i2The second interval.
i_outThe output intersection interval, possibly empty.
Returns
TRUE if i_out is not empty.

Definition at line 285 of file interval.c.

References Tinterval::lower_limit, and Tinterval::upper_limit.

Referenced by BoxesIntersection(), BoxSaddleClipping(), BoxSphereClipping(), CropLinearConstraint(), Intersect(), RectangleCircleClipping(), RectangleParabolaClipping(), SegmentCircleIntersection(), SegmentSphereIntersection(), SimplifyLinearConstraint(), and UpdateOriginalFromSimple().

boolean Union ( Tinterval i1,
Tinterval i2,
Tinterval i_out 
)

Computes the union of two intervals.

Parameters
i1The first interval.
i2The second interval.
i_outThe output union interval, possibly empty.
Returns
TRUE if i_out is not empty. The union of two intervals is empty if the two input intervals were empty.

Definition at line 297 of file interval.c.

References FALSE, Tinterval::lower_limit, TRUE, and Tinterval::upper_limit.

Referenced by BoxSphereClipping(), BoxUnion(), RectangleCircleClipping(), and RectangleParabolaClipping().

boolean EmptyInterval ( Tinterval i)

Checks if a given interval is empty.

Parameters
iThe interval to check.
Returns
TRUE if i is empty.

Definition at line 335 of file interval.c.

References Tinterval::lower_limit, and Tinterval::upper_limit.

Referenced by PrintInterval(), PrintSymbolInterval(), ReduceRange(), SegmentCircleIntersection(), and SegmentSphereIntersection().

boolean IsInside ( double  p,
double  tol,
Tinterval i 
)

Checks if a value is inside an interval.

Parameters
pThe value
tolTolerance in the comparison.
iThe interval.
Returns
TRUE if the point is inside the interval.

Definition at line 343 of file interval.c.

References INF_CUT, Tinterval::lower_limit, and Tinterval::upper_limit.

Referenced by AddEquation2Simplex(), BoxSaddleClipping(), IntervalDivision(), IntervalPow(), PointInBox(), PointInBoxTopology(), PointInSubBox(), PointInSystemBox(), SegmentCircleIntersection(), and SegmentSphereIntersection().

void IntervalScale ( Tinterval i1,
double  e,
Tinterval i_out 
)
void IntervalSubstract ( Tinterval i1,
Tinterval i2,
Tinterval i_out 
)

Substraction of two intervals.

Parameters
i1The first interval.
i2The second interval.
i_outThe resulting interval.

Definition at line 437 of file interval.c.

References FALSE, INF_CUT, INF_SUBS, Tinterval::lower_limit, ROUNDDOWN, ROUNDNEAR, ROUNDUP, TRUE, and Tinterval::upper_limit.

Referenced by CleanInfEquation(), SegmentCircleIntersection(), and SegmentSphereIntersection().

void IntervalInvert ( Tinterval i,
Tinterval i_out 
)

Change of sign of a given interval. Equivalen to scale the interval with -1.

Parameters
iThe input interval.
i_outThe resulting interval.

Definition at line 456 of file interval.c.

References Tinterval::lower_limit, and Tinterval::upper_limit.

Referenced by BoxSaddleClipping(), BoxSphereClipping(), GetFirstOrderApproximationToEquation(), InvertLinearConstraint(), PrintLinearConstraint(), RectangleCircleClipping(), RectangleParabolaClipping(), SegmentCircleIntersection(), SegmentSphereIntersection(), and UpdateOriginalFromSimple().

void IntervalExp ( Tinterval i,
Tinterval i_out 
)

Computes the exponentional of a given interval.

Parameters
iThe input interval.
i_outThe resulting interval.

Definition at line 470 of file interval.c.

References INF_CUT, INF_EXP, Tinterval::lower_limit, ROUNDDOWN, ROUNDNEAR, ROUNDUP, and Tinterval::upper_limit.

Referenced by EvaluateVarSetInt().

void IntervalPow ( Tinterval i,
unsigned int  p,
Tinterval i_out 
)
boolean IntervalSqrt ( Tinterval i,
Tinterval i_out 
)

Computes the square root of an interval. Negative parts of the interval are not taken into account. If the whole input interval is negative the result is an empty interval.

Parameters
iThe input interval.
i_outThe resulting interval.
Returns
TRUE if the output interval is NULL.

Definition at line 525 of file interval.c.

References FALSE, INF_CUT, INF_SQRT, Tinterval::lower_limit, ROUNDDOWN, ROUNDNEAR, ROUNDUP, TRUE, and Tinterval::upper_limit.

Referenced by BoxSphereClipping(), NewInPatchJoint(), RectangleCircleClipping(), RectangleParabolaClipping(), SegmentCircleIntersection(), and SegmentSphereIntersection().

void IntervalDivision ( Tinterval num,
Tinterval den,
Tinterval i_out 
)

Divides one interval by another. If the denominator includes the zero, this function triggers an error.

Parameters
numThe interval numerator.
denThe interval denominator.
i_outThe resulting interval.

Definition at line 551 of file interval.c.

References INF, INF_CUT, IsInside(), Tinterval::lower_limit, ROUNDDOWN, ROUNDNEAR, ROUNDUP, and Tinterval::upper_limit.

Referenced by BoxSaddleClipping(), CropLinearConstraint(), IntervalSecant2(), SegmentCircleIntersection(), SegmentSphereIntersection(), and SimplifyLinearConstraint().

void IntervalOffset ( Tinterval i,
double  offset,
Tinterval i_out 
)
void IntervalSine ( Tinterval i,
Tinterval i_out 
)

Computes the bound of the sinus on a given interval.

Parameters
iThe input interval.
i_outThe resulting interval.

Definition at line 642 of file interval.c.

References IntervalSize(), Tinterval::lower_limit, M_2PI, M_PI_2, NewInterval(), NormalizeAngle(), and Tinterval::upper_limit.

Referenced by EvaluateVarSetInt().

void IntervalCosine ( Tinterval i,
Tinterval i_out 
)

Computes the bound of the cosinus on a given interval.

Parameters
iThe input interval.
i_outThe resulting interval.

Definition at line 697 of file interval.c.

References IntervalSize(), Tinterval::lower_limit, M_2PI, M_PI, NewInterval(), NormalizeAngle(), and Tinterval::upper_limit.

Referenced by EvaluateVarSetInt(), GenerateJointRangeEquations(), IntCosVector(), IntervalSecant2(), and IntSinVector().

void IntervalTangent ( Tinterval i,
Tinterval i_out 
)

Computes the bound of the tangent on a given interval.

Parameters
iThe input interval.
i_outThe resulting interval.

Definition at line 749 of file interval.c.

References INF, IntervalSize(), Tinterval::lower_limit, M_2PI, M_PI_2, NewInterval(), NormalizeAngle(), and Tinterval::upper_limit.

Referenced by EvaluateVarSetInt(), and IntervalSecant2Tangent().

void IntervalSecant2 ( Tinterval i,
Tinterval i_out 
)

Computes the bound of the squared secant on a given interval.

Parameters
iThe input interval.
i_outThe resulting interval.

Definition at line 841 of file interval.c.

References IntervalCosine(), IntervalDivision(), IntervalPow(), and NewInterval().

Referenced by EvaluateVarSetInt().

void IntervalSecant2Tangent ( Tinterval i,
Tinterval i_out 
)

Computes the bound of the squared secant on a given interval per its tangent.

Parameters
iThe input interval.
i_outThe resulting interval.

Definition at line 851 of file interval.c.

References INF, IntervalSize(), IntervalTangent(), Tinterval::lower_limit, M_2PI, M_PI_2, NewInterval(), NormalizeAngle(), and Tinterval::upper_limit.

Referenced by EvaluateVarSetInt().

void IntervalAtan2 ( Tinterval is,
Tinterval ic,
Tinterval i_out 
)

Computes the bound of the atan2 on a given sin/cos intervals.

The current implementation is tailored to post-process solution files and in only works for small intervals.

The output in in the range $[-\pi,\pi]$ except for the case where is and ic include (-1,0). In this case the output interval is in the range $[0,2\:\pi]$.

Parameters
isThe sinus interval.
icThe cosinus interval.
i_outThe resulting interval.

Definition at line 952 of file interval.c.

References Error(), IntervalSize(), Tinterval::lower_limit, M_2PI, M_PI, and Tinterval::upper_limit.

Referenced by main().

void PrintSymbolInterval ( FILE *  f,
Tinterval i 
)

Writes an interval to a stream that can be stdout. Values like +/-PI or +/-PI/2 are printed symbolically to avoid rounding.

This should only be used for angular variables.

Parameters
fThe strem.
iThe interval to write.

Definition at line 986 of file interval.c.

References EmptyInterval(), Tinterval::lower_limit, SYMBOL_PRINT, and Tinterval::upper_limit.

Referenced by PrintVariable().

void PrintInterval ( FILE *  f,
Tinterval i 
)
void DeleteInterval ( Tinterval i)

Deletes an interval structure.

Parameters
iThe interval to delete.

Definition at line 1016 of file interval.c.

Referenced by DeleteJoint(), DeleteLinearConstraint(), GenerateEquationsFromBranch(), GenerateJointEquations(), GenerateJointRangeEquations(), and main().