Skip to content

Instantly share code, notes, and snippets.

@mashbridge
mashbridge / cubegen.cc
Created November 22, 2013 06:47
Create cubic polygons in KML
// This program accepts a center point (lat, lng, alt) and a distance (in m)
// and generates a cube of side distance around that point.
// e.g. ./cubegen 37.0 -122.0 1000 200
#include <iostream>
#include <string>
#include <vector>
#include "kml/base/math_util.h"
#include "kml/dom.h"
@mashbridge
mashbridge / Makefile
Created November 22, 2013 04:53
Poisson surface reconstruction Example
#
# Assumes headers and libs in /usr/local/. You'll need eigen3 or another
# solver library. On OS X you can maybe do:
# brew install eigen
# brew install cgal --imaging --with-eigen3 --with-lapack
#
IDIRS = /usr/local/include /usr/local/include/eigen3
LDIRS = /usr/local/lib
INCS = $(foreach d, $(IDIRS), -I$d)
@mashbridge
mashbridge / gmap-circle.js
Last active December 27, 2015 13:18
Using the Google Maps API v3 to draw a circle of given radius around a point.
// Given c as google.maps.LatLng, r in meters.
function drawCircle(c, r) {
var cLat = c.lat() * Math.PI / 180;
var cLng = c.lng() * Math.PI / 180;
var d = r / 6378137.0;
var paths = [];
// http://williams.best.vwh.net/avform.htm#LL
// Using 64 segments.
for (var tc = 0; tc < 2 * Math.PI; tc += (Math.PI / 32)) {
var lat = Math.asin(Math.sin(cLat) * Math.cos(d)

The size of Wales.

To build wales.json:

curl -O "http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_map_subunits.zip" && unzip ne_10m_admin_0_map_subunits.zip && ogr2ogr -f GeoJSON -where "SUBUNIT IN ('Wales')" wales.subunit.json ne_10m_admin_0_map_subunits.shp && topojson --id-property su_a3 -p name=NAME -p name -o wales.json wales.subunit.json

@mashbridge
mashbridge / README.md
Last active December 24, 2015 18:19
<spoiler>

David Friedman wondered aloud about a <spoiler> element. The Web Components proposal will allow custom HTML elements. This is an example of an <x-spoiler> element (the spec requires a hypen in the name) implemented using Google's Polymer library.

Click on the obscured text to reveal the spoiler.

@mashbridge
mashbridge / pointinpolygon.cc
Created April 26, 2013 00:08
A basic point-in-polygon test using libkml.
// Implements a basic point-in-polygon test using libkml.
#include <assert.h>
#include <iostream>
#include <string>
#include "kml/base/vec3.h"
#include "kml/dom.h"
using kmlbase::Vec3;
@mashbridge
mashbridge / arraydepth.go
Created December 24, 2012 08:22
How to calculate the dimensionality of an array in Go
func ArrayDepth(i interface{}) int {
return arrayDepth(i, 0)
}
func arrayDepth(i interface{}, n int) int {
kind := reflect.ValueOf(i).Kind()
if kind == reflect.Array || kind == reflect.Slice {
n += 1
j := i.([]interface{})
return arrayDepth(j[0], n)
// For large numbers of math.Pow(x,y) calls, it's worth special-casing y=2
// and squaring it yourself.
package main
import (
"flag"
"fmt"
"math"
)