Skip to content

Instantly share code, notes, and snippets.

@jamesgregson
jamesgregson / jacobian_fd.py
Last active October 4, 2020 23:31
Finite difference Jacobians of numeric functions
'''Finite difference Jacobians
Author: James Gregson
Date: 2020-10-04
Utility function to differentiate numeric functions with finite differences.
Useful for checking analytically derived Jacobian & gradient computations.
See bottom of file for example usage.
@jamesgregson
jamesgregson / ik.py
Last active October 16, 2020 05:01
Simple & compact damped least-squares IK solver in <100 lines of python
'''
[email protected]
A pretty small 3D IK solver, < 100 lines of code but > 100 lines of comments.
Low dependency (numpy, opencv-python, matplotlib) and includes visualization.
Not particularly fast.
Solves for joint rotations needed in a kinematic skeleton to minimize errors of a set
of end-effectors with respect to a corresponding set of target positions. Assumes
@jamesgregson
jamesgregson / ostream-helpers.h
Last active August 25, 2024 19:51
C++ output operators for std::array and std::tuple
#pragma once
#include <array>
#include <tuple>
#include <iostream>
// use this namespace to expose operators
namespace ostream_helpers {
namespace {
@jamesgregson
jamesgregson / lex-expr-example.cpp
Created October 24, 2024 01:54
C++20 PEG parser
#include "lex.h"
#include <iostream>
struct ParserState {
lex::UserFnRegistry<const char*> user_fns;
std::vector<double> stack;
void push( const double & v ){
stack.push_back( v );