constraints.types.angle.AngleConstraint
constraints.types.angle.AngleConstraint(vector1, vector2, angle, *, weight=1.0)Constraint that fixes the angle between two vectors.
This constraint enforces: arccos(v1 · v2 / (||v1|| ||v2||)) = angle
Reduces DOF by 1 (one scalar equation).
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| vector1 | Vector | First direction vector (Vector parameter) | required |
| vector2 | Vector | Second direction vector (Vector parameter) | required |
| angle | Scalar | float | Target angle in radians (Scalar parameter or float) | required |
Example
v1 = Vector([1, 0, 0], free=True, name='v1')
v2 = Vector([0, 1, 0], free=True, name='v2')
constraint = AngleConstraint(v1, v2, jnp.pi / 2)Methods
| Name | Description |
|---|---|
| compute_residual | Compute angle constraint residual: v1·v2/(||v1||||v2||) - cos(θ). |
| dof_reduction | Angle constraint adds 1 scalar equation, reducing DOF by 1. |
| get_parameters | Return both vectors involved in the angle constraint. |
compute_residual
constraints.types.angle.AngleConstraint.compute_residual(param_values)Compute angle constraint residual: v1·v2/(||v1||||v2||) - cos(θ).
Using cos(θ) instead of arccos avoids singularities at 0/π where the arccos gradient vanishes, which can stall the LM solver.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| param_values | dict[str, Array] | Dict with keys matching parameter names | required |
Returns
| Name | Type | Description |
|---|---|---|
| Array | Scalar residual (0 when constraint is satisfied) |
dof_reduction
constraints.types.angle.AngleConstraint.dof_reduction()Angle constraint adds 1 scalar equation, reducing DOF by 1.
get_parameters
constraints.types.angle.AngleConstraint.get_parameters()Return both vectors involved in the angle constraint.