Skip to content

Instantly share code, notes, and snippets.

@dbruning
Created July 25, 2020 19:17
Show Gist options
  • Save dbruning/69bb5e0623d3c2aa64cede73a0b86542 to your computer and use it in GitHub Desktop.
Save dbruning/69bb5e0623d3c2aa64cede73a0b86542 to your computer and use it in GitHub Desktop.
Calculation of hop mesh for thereandbackagain.nz
function getHopMesh(row, toEastingField, toNorthingField, transportMode, material, topHalf) {
let from = {
x: eastingToMap(row.data.SA2_usual_residence_easting),
y: northingToMap(row.data.SA2_usual_residence_northing)
}
let to = {
x: eastingToMap(row.data[toEastingField]),
y: northingToMap(row.data[toNorthingField])
}
let midpoint = {
x: (from.x + to.x) / 2,
y: (from.y + to.y) / 2
}
let op = to.y - from.y;
let ad = to.x - from.x;
let theta = Math.atan2(op , ad);
let hy = Math.sqrt(Math.pow(op, 2) + Math.pow(ad, 2))
let radius = hy / 2
let tubeDiameter = row.data[transportMode] / 5000;
let arc = (topHalf)? Math.Pi : 2 * Math.Pi;
let geometry = new Three.TorusGeometry(radius, tubeDiameter, 8, 10, arc);
geometry.rotateX(Math.PI / 2)
let mesh = new Three.Mesh(geometry, material);
mesh.rotateZ(theta)
mesh.position.x = midpoint.x
mesh.position.y = midpoint.y
mesh.position.z = 0;
return mesh;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment