Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

VectorNormFactor

This API walkthrough introduces the wrapped classes VectorNormFactor declared by VectorNormFactor.h and demonstrates their principal Python operations.

Open In Colab

Overview

VectorNormFactor<N> is a unary factor constraining the norm of an N-dimensional vector-space variable to a given value, with error

e=∥v∥−norm,∂e∂v=vT∥v∥.e = \lVert v \rVert - \text{norm}, \qquad \frac{\partial e}{\partial v} = \frac{v^T}{\lVert v \rVert}.

The typical use is a magnitude pseudo-observation on a physical vector whose direction and magnitude are entangled in a single variable:

  • an estimated gravity vector, paired with ImuFactorWithGravityVector (Lupton and Sukkarieh, 2012), or

  • a local magnetic field vector estimated with MagFactor2, whose magnitude is often known from the NOAA tables even when its direction in the nav frame is not.

Add it once per variable: adding it per measurement factor would count the same prior knowledge multiple times. The N=3 instantiation is available in Python as VectorNormFactor3.

Warning: the error is not differentiable at ∥v∥=0\lVert v \rVert = 0; the Jacobian is zero there, so a variable initialized at exactly zero receives no gradient from this factor and will not move. Always initialize with a non-zero guess.

Usage Example

A loose vector prior fixes the direction; the norm factor pulls the magnitude to the target along that direction.

optimized vector: [5.6638 5.6638 5.6638]
norm: 9.81000 (target 9.81)

Key Functionality / API

  • VectorNormFactor3(key, norm, noiseModel): constrain a Point3/Vector3 variable.

  • norm(): the target norm.

  • With a noiseModel::Constrained model it acts as a hard constraint under QR-based elimination (not recommended with Cholesky). If the norm is known exactly, prefer a parametrization that fixes it instead, eg. Unit3 with a fixed magnitude (ImuFactorWithGravityDirection).

Source