Skip to content

Instantly share code, notes, and snippets.

View elijahzarlin's full-sized avatar

Elijah Zarlin elijahzarlin

View GitHub Profile
@elijahzarlin
elijahzarlin / world-scale-ar-1.swift
Last active September 13, 2018 18:21
world scale ar post
func azimuthBetween(origin: CLLocation, destination: CLLocation) -> Float {
var azimuth: Float = 0
let originLatitude = GLKMathDegreesToRadians(Float(origin.coordinate.latitude))
let originLongitude = GLKMathDegreesToRadians(Float(origin.coordinate.longitude))
let destinationLatitude = GLKMathDegreesToRadians(Float(destination.coordinate.latitude))
let destinationLongitude = GLKMathDegreesToRadians(Float(destination.coordinate.longitude))
let dLon = destinationLongitude - originLongitude
@elijahzarlin
elijahzarlin / world-scale-ar-rotate.swift
Last active September 13, 2018 18:34
world-scale-ar-2
func transformMatrix(originLocation: CLLocation, destinationLocation: CLLocation) -> simd_float4x4 {
let azimuth = azimuthBetween(origin: originLocation, destination: destinationLocation)
// Place POIs "z" meters away from camera
let position = vector_float4(0, 0, -10, 0)
let translationMatrix = matrix_identity_float4x4.translationMatrix(position)
// Rotate POI based on azimuth
let rotationMatrix = matrix_identity_float4x4.rotationAroundY(radians: azimuth)
@elijahzarlin
elijahzarlin / world-scale-ar-class.swift
Created September 13, 2018 18:36
world-scale-ar-3
internal extension matrix_float4x4 {
func rotationAroundY(radians: Float) -> matrix_float4x4 {
var matrix: matrix_float4x4 = self
matrix.columns.0.x = cos(radians)
matrix.columns.0.z = -sin(radians)
matrix.columns.2.x = sin(radians)
matrix.columns.2.z = cos(radians)
@elijahzarlin
elijahzarlin / emerald-star-1.js
Last active September 14, 2018 18:40
rock n' roll cartographer
var locations = turf.featureCollection([
turf.point([latitude, longitude]),
turf.point([latitude, longitude])
]);
var user = turf.point([latitude, longitude]);
@elijahzarlin
elijahzarlin / emerald-star-2.js
Created September 14, 2018 18:42
rock n roll turn
var nearest = turf.nearestPoint(user, locations);
var bearing = turf.bearingToAzimuth(turf.bearing(user, nearest));
var distance = turf.distance(user, nearest, { units: meters });
if (distance < 50) {
// Unlock Emerald Star
}
@elijahzarlin
elijahzarlin / arc-layer-deck-gl.js
Last active October 12, 2018 19:35
arc layer deck gl
const map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/light-v9",
center: [-122.398, 37.788],
zoom: 12,
pitch: 60
});
map.on("style.load", () => {
// Get data for the arc map from SFMTA origin/destination routes
@elijahzarlin
elijahzarlin / hurricane-map-2.js
Created October 23, 2018 18:48
hurricane-map-2
let bearing = ruler.bearing(firstPoint, nextPoint);
let p1 = ruler.destination(nextPoint, errorRadius, bearing + 90);
let p2 = ruler.destination(firstPoint, acc.prevPoint.errorRadius, bearing + 90);
let p3 = ruler.destination(firstPoint, acc.prevPoint.errorRadius, bearing - 90);
let p4 = ruler.destination(nextPoint, errorRadius, bearing - 90);
const polygon = turf.polygon([[p1, p2, p3, p4, p1]]);
@elijahzarlin
elijahzarlin / hurricane-map-1.js
Last active October 23, 2018 18:50
hurricane-map-1
const errorRadiusKm = ruler.distance([item.lon, item.lat], [item.lon + errorRadiusDeg, item.lat]);
const circle = turf.circle([item.lon, item.lat], errorRadiusKm, {steps: 32, units: 'kilometers'});
@elijahzarlin
elijahzarlin / hurricane-map-3.js
Last active October 23, 2018 19:31
hurricane-map-3
[
"interpolate",
["linear"],
["get", "WindSpeed.Kph"],
55,
"hsl(47, 100%, 90%)",
120,
"hsl(340, 100%, 82%)",
220,
"#ff0040"
@elijahzarlin
elijahzarlin / hurricane-map-4.js
Last active October 23, 2018 19:32
hurricane-map-4
[
"interpolate",
["linear"],
["zoom"],
2,
[
"/",
[
"max",
[