## Signed angle between two 3D vectors with same origin within the same plane

The solution I’m currently using seems to be missing here. Assuming that the plane normal is normalized (|Vn| == 1), the signed angle is simply: For the right-handed rotation from Va to Vb: atan2((Va x Vb) . Vn, Va . Vb) For the left-handed rotation from Va to Vb: atan2((Vb x Va) . Vn, Va … Read more

## What is “entropy and information gain”?

I assume entropy was mentioned in the context of building decision trees. To illustrate, imagine the task of learning to classify first-names into male/female groups. That is given a list of names each labeled with either m or f, we want to learn a model that fits the data and can be used to predict … Read more

## Quadratic Bézier Curve: Calculate Points

Use the quadratic Bézier formula, found, for instance, on the Wikipedia page for Bézier Curves: In pseudo-code, that’s t = 0.5; // given example value x = (1 – t) * (1 – t) * p.x + 2 * (1 – t) * t * p.x + t * t * p.x; y = (1 … Read more

## Smart design of a math parser?

A pretty good approach would involve two steps. The first step involves converting the expression from infix to postfix (e.g. via Dijkstra’s shunting yard) notation. Once that’s done, it’s pretty trivial to write a postfix evaluator.

## Calculating a LookAt matrix

Note the example given is a left-handed, row major matrix. So the operation is: Translate to the origin first (move by –eye), then rotate so that the vector from eye to At lines up with +z: Basically you get the same result if you pre-multiply the rotation matrix by a translation –eye: [ 1 0 … Read more

## How to test randomness (case in point – Shuffling)

Statistics. The de facto standard for testing RNGs is the Diehard suite (originally available at http://stat.fsu.edu/pub/diehard). Alternatively, the Ent program provides tests that are simpler to interpret but less comprehensive. As for shuffling algorithms, use a well-known algorithm such as Fisher-Yates (a.k.a “Knuth Shuffle”). The shuffle will be uniformly random so long as the underlying … Read more

## What does the ^ (XOR) operator do? [duplicate]

XOR is a binary operation, it stands for “exclusive or”, that is to say the resulting bit evaluates to one if only exactly one of the bits is set. This is its function table: a | b | a ^ b –|—|—— 0 | 0 | 0 0 | 1 | 1 1 | 0 … Read more

## Rotating a Vector in 3D Space

If you want to rotate a vector you should construct what is known as a rotation matrix. Rotation in 2D Say you want to rotate a vector or a point by θ, then trigonometry states that the new coordinates are x’ = x cos θ − y sin θ y’ = x sin θ + … Read more

## Calculate the center point of multiple latitude/longitude coordinate pairs

Thanks! Here is a C# version of OP’s solutions using degrees. It utilises the System.Device.Location.GeoCoordinate class public static GeoCoordinate GetCentralGeoCoordinate( IList<GeoCoordinate> geoCoordinates) { if (geoCoordinates.Count == 1) { return geoCoordinates.Single(); } double x = 0; double y = 0; double z = 0; foreach (var geoCoordinate in geoCoordinates) { var latitude = geoCoordinate.Latitude * Math.PI … Read more

## Nth Combination

Note you can generate the sequence by recursively generating all combinations with the first element, then all combinations without. In both recursive cases, you drop the first element to get all combinations from n-1 elements. In Python: def combination(l, r): if r == 0: yield [] elif len(l) == r: yield l else: for c … Read more