Loading...
Searching...
No Matches
UnitTest_SolveStretchConstraint Class Reference

## Public Member Functions

IEnumerator | PerformUnitTests ()

## Private Member Functions

void | PickRandomPositions (out Vector3 particlePositionOne, out Vector3 particlePositionTwo)
void | Test_SolveStretchConstraint (int iterations, Vector3 particlePositionOne, Vector3 particlePositionTwo, BSM.Quaternion orientation, GuidewireSim.MathHelper mathHelper, GuidewireSim.ConstraintSolvingStep constraintSolvingStep)

## Private Attributes

float | maximalDistanceOffset = 1f
int | sampleSize = 10
int | constraintSolverSteps = 1000
| How often the constraint solver iterates over each constraint during the Constraint Solving Step. More...
float | rodElementLength = 10f
| The distance between two spheres, also the distance between two orientations. More...

## Detailed Description

This class provides unit tests that test the method SolveStretchConstraint() of ConstraintSolvingStep. Executing this test once generates `sampleSize` many random value pairs and executes the unit test with each of these pairs.

## Member Function Documentation

## PerformUnitTests()

IEnumerator UnitTest_SolveStretchConstraint.PerformUnitTests | ( |  | ) |

Arranges all necessary data, generates sampleSize many random value pairs, and then passes all data to Test_SolveStretchConstraint(), where the unit tests are executed.

## PickRandomPositions()

void UnitTest_SolveStretchConstraint.PickRandomPositions | ( | out Vector3 | particlePositionOne,
|  | out Vector3 | particlePositionTwo
| ) |  |

private

Picks the first particle position uniformly distributed with \( x,y,z \in [-5, 5] \) and the second uniformly distributed around the first position with a uniformly distributed distance in \( [rodElementLength - maximalDistanceOffset, rodElementLength + maximalDistanceOffset] \).

Note
  The method for picking the second position is inspired by https://math.stackexchange.com/q/50482

Parameters

  [out] | particlePositionOne | The first particle position that got picked.
  [out] | particlePositionTwo | The second particle position that got picked.

Requirements:

  Picks the first particle position uniformly distributed so that \( x,y,z \in [-5, 5] \).

  Picks a distance between the two particles that is uniformly distributed in the interval \( [rodElementLength - maximalDistanceOffset, rodElementLength + maximalDistanceOffset] \).

  Picks the second particle position uniformly distributed on the surface of the sphere with center `particlePositionOne` and radius `startDistance`.

## Test_SolveStretchConstraint()

void UnitTest_SolveStretchConstraint.Test_SolveStretchConstraint | ( | int | iterations,
|  | Vector3 | particlePositionOne,
|  | Vector3 | particlePositionTwo,
|  | BSM.Quaternion | orientation,
|  | GuidewireSim.MathHelper | mathHelper,
|  | GuidewireSim.ConstraintSolvingStep | constraintSolvingStep
| ) |  |

private

Executes SolveStretchConstraint() of ConstraintSolvingStep `iterations` many times for one values pair, and then asserts whether the results of the algorithm of SolveStretchConstraint() converged towards the expected values.

Parameters

  iterations | The number of iterations that SolveStretchConstraint() of ConstraintSolvingStep is executed.
  particlePositionOne | The first particle position for SolveStretchConstraint().
  particlePositionTwo | The second particle position for SolveStretchConstraint().
  orientation | The orientation for SolveStretchConstraint().
  mathHelper | The component MathHelper.
  constraintSolvingStep | The component ConstraintSolvingStep.

Requirements:

  `orientation` is still a unit quaternion at the end of the test.

  The deviation between the stretch constraint and zero is lower than the tolerance 0.1, which means that the algorithm of SolveStretchConstraint() converges towards the fulfillment of the stretch constraint.

  The deviation between the actual distance of `particlePositionOne` and `particlePositionTwo` and the rest rod element length is lower than a reasonable tolerance, i.e. close to zero.

Attention
  The fulfillment of the requirement that the rod element length converges towards the rest rod element length depends on the initial deviation of both particle positions from each other and is just a byproduct of converging towards the constraint fulfillment. If this requirement is not fulfilled, the initial offset or the number of iterations was probably simply to high or low, respectively.

## Member Data Documentation

## constraintSolverSteps

int UnitTest_SolveStretchConstraint.constraintSolverSteps = 1000

private

How often the constraint solver iterates over each constraint during the Constraint Solving Step.

## maximalDistanceOffset

float UnitTest_SolveStretchConstraint.maximalDistanceOffset = 1f

private

The maximal deviation from the rest `rodElementLength`.

Example
  Let `rodElementLength` be 10 and maximalDistanceOffset be 2. Then the two random particle positions drawn will have a distance between 8 and 12.

## rodElementLength

float UnitTest_SolveStretchConstraint.rodElementLength = 10f

private

The distance between two spheres, also the distance between two orientations.

## sampleSize

int UnitTest_SolveStretchConstraint.sampleSize = 10

private

The number of value-pairs the test is executed with. E.g. if sampleSize is 10, then the unit test is executed with 10 randomly drawn value-pairs. A higher number needs more time to execute.

The documentation for this class was generated from the following file:

- UnitTest_SolveStretchConstraint.cs