pocket-physics
Version:
Verlet physics extracted from pocket-ces demos
16 lines (15 loc) • 482 B
JavaScript
import { v2, sub, normalize, scale, add } from "./v2";
// preallocations
const v = v2();
const direction = v2();
const radiusSegment = v2();
/**
* Compute the leading edge of a circular moving object given a radius: cpos + radius in the direction of velocity.
*/
export const projectCposWithRadius = (out, p, radius) => {
sub(v, p.cpos, p.ppos);
normalize(direction, v);
scale(radiusSegment, direction, radius);
add(out, radiusSegment, p.cpos);
return out;
};