Calculating distance between zip codes in PHP

This is mike’s answer with some annotations for the magic numbers. It seemed to work fine for me for some test data: function calc_distance($point1, $point2) { $radius = 3958; // Earth’s radius (miles) $deg_per_rad = 57.29578; // Number of degrees/radian (for conversion) $distance = ($radius * pi() * sqrt( ($point1[‘lat’] – $point2[‘lat’]) * ($point1[‘lat’] – … Read more

get closest point to a line

Here’s Ruby disguised as Pseudo-Code, assuming Point objects each have a x and y field. def GetClosestPoint(A, B, P) a_to_p = [P.x – A.x, P.y – A.y] # Storing vector A->P a_to_b = [B.x – A.x, B.y – A.y] # Storing vector A->B atb2 = a_to_b[0]**2 + a_to_b[1]**2 # **2 means “squared” # Basically finding … Read more

How to calculate Tangent and Binormal?

The relevant input data to your problem are the texture coordinates. Tangent and Binormal are vectors locally parallel to the object’s surface. And in the case of normal mapping they’re describing the local orientation of the normal texture. So you have to calculate the direction (in the model’s space) in which the texturing vectors point. … Read more

Fitting polynomials to data

Thanks for everyone’s replies. Here is another attempt at summarizing them. Pardon if I say too many “obvious” things: I knew nothing about least squares before, so everything was new to me. NOT polynomial interpolation Polynomial interpolation is fitting a polynomial of degree n given n+1 data points, e.g. finding a cubic that passes exactly … Read more