Derivates

This is an example of how to use the Symbol class to differentiate a function. The function we are using is

    Vec2 projectPoint(
              const Scalar R[3], // The compact angle-axis rotation of the camera.
              const Scalar T[3], // The translation of the camera.
              const Scalar& f,  // The focal length of the camera.
              const Scalar& l1, // The first distortion parameter of the camera.
              const Scalar& l2, // The second distortion parameter of the camera.
              const Scalar P[3]  // The world point.
        ) const 
    {
        // Rotate P around R and translate by T:    
        const Vec3 p = rotate(Vec3::Map(R), Vec3::Map(P)) + Vec3::Map(T);
  
        // Compute the center of distortion.
        const Vec2 cx = -p.hnormalized();
  
        // Apply second and fourth order radial distortion.
        const Scalar r2 = cx.squaredNorm();
        const Scalar distortion = 1 + r2*(l1 + r2*l2);
  
        // Compute final projected point position.
        return f * distortion * cx;
    }
    

TODO: Work in progress.

You can find the full source code of this example here.