## Drawing part of a Bézier curve by reusing a basic Bézier-curve-function?

What you need is the De Casteljau algorithm. This will allow you to split your curve into whatever segments you’d like. However, since you’re dealing with just cubic curves, I’d like to suggest a slightly easier to use formulation that’ll give you a segment from t0 to t1 where 0 <= t0 <= t1 <= … Read more

## Get direction (compass) with two longitude/latitude points

O forgot to say I found the answer eventually. The application is to determine compass direction of a transit vehicle and its destination. Essentially, fancy math for acquiring curvature of Earth, finding an angle/compass reading, and then matching that angle with a generic compass value. You could of course just keep the compassReading and apply … Read more

## OpenGL Math – Projecting Screen space to World space coords

RESOLVED Here’s how to do it exactly, step by step. Obtain your mouse coordinates within the client area Get your Projection matrix and View matrix if no Model matrix required. Multiply Projection * View Inverse the results of multiplication Construct a vector4 consisting of x = mouseposition.x within a range of window x transform to … Read more

## Get bounds of rotated rectangle

Known data: bounding box width W, height H, rotation angle Fi Wanted: coordinates of rotated rectangle vertices. Unknown source rectangle size: w x h Bounding box size for this dimension and rotation angle: H = w * Abs(Sin(Fi)) + h * Abs(Cos(Fi)) W = w * Abs(Cos(Fi)) + h * Abs(Sin(Fi)) denote as = Abs(Sin(Fi)) … Read more

## How are exponents calculated?

I’ve had a chance to look at fdlibm’s implementation. The comments describe the algorithm used: * n * Method: Let x = 2 * (1+f) * 1. Compute and return log2(x) in two pieces: * log2(x) = w1 + w2, * where w1 has 53-24 = 29 bit trailing zeros. * 2. Perform y*log2(x) = … Read more

Solving quadratic equations is not as simple as most people think. The standard formula for solving a x^2 + b x + c = 0 is delta = b^2 – 4 a c x1 = (-b + sqrt(delta)) / (2 a) (*) x2 = (-b – sqrt(delta)) / (2 a) but when 4 a c … Read more

## Max square size for unknown number inside rectangle

Conceptually: start with 1 square For each additional square, if you don’t have room in your grid box so far, shrink the existing box just enough to make room for an additional row or column. pseudocode: given M x N rectangle to fill with K squares // initial candidate grid within the rectangle h=1 w=1 … Read more

## What is the difference between ‘precision’ and ‘accuracy’? [closed]

Precision refers to how much information is conveyed by a number (in terms of number of digits) whereas accuracy is a measure of “correctness”. Let’s take the π approximation 22/7, for our purposes, 3.142857143. For your specific questions: a number that is accurate but not precise: 3.14. That’s certainly accurate in terms of closeness, given … Read more

## Difference between some operators “|”, “^”, “&”, “&^”. Golang

Bitwise operators come into play when you have to work with byte- or bit-level data. Here I list a handful of examples using bit operations with code samples (in no particular order): 1. They are common and part of many algorithms in cryptography and hash functions (e.g. MD5). 2. They are also often used if … Read more

## How to best approximate a geometrical arc with a Bezier curve?

This is an 8-year-old question, but one that I recently struggled with, so I thought I’d share what I came up with. I spent a lot of time trying to use solution (9) from this article by Aleksas Riškus and couldn’t get any sensible numbers out of it until I did some Googling and learned … Read more