How to determine if a list of polygon points are in clockwise order?

Some of the suggested methods will fail in the case of a non-convex polygon, such as a crescent. Here’s a simple one that will work with non-convex polygons (it’ll even work with a self-intersecting polygon like a figure-eight, telling you whether it’s mostly clockwise). Sum over the edges, (x2 − x1)(y2 + y1). If the … Read more

Calculate distance between 2 GPS coordinates

Calculate the distance between two coordinates by latitude and longitude, including a Javascript implementation. West and South locations are negative. Remember minutes and seconds are out of 60 so S31 30′ is -31.50 degrees. Don’t forget to convert degrees to radians. Many languages have this function. Or its a simple calculation: radians = degrees * … Read more

Understanding “randomness”

Just a clarification Although the previous answers are right whenever you try to spot the randomness of a pseudo-random variable or its multiplication, you should be aware that while Random() is usually uniformly distributed, Random() * Random() is not. Example This is a uniform random distribution sample simulated through a pseudo-random variable: BarChart[BinCounts[RandomReal[{0, 1}, 50000], … Read more

Designing function f(f(n)) == -n

You didn’t say what kind of language they expected… Here’s a static solution (Haskell). It’s basically messing with the 2 most significant bits: f :: Int -> Int f x | (testBit x 30 /= testBit x 31) = negate $ complementBit x 30 | otherwise = complementBit x 30 It’s much easier in a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)