Skip to content

Instantly share code, notes, and snippets.

@evan-goode
Created October 28, 2018 04:12
Show Gist options
  • Save evan-goode/9d619b0164e406454aaf561e17a47cbf to your computer and use it in GitHub Desktop.
Save evan-goode/9d619b0164e406454aaf561e17a47cbf to your computer and use it in GitHub Desktop.
minecraft stronghold finder
<input placeholder="X #1" id="a-y">
<input placeholder="Z #1" id="a-x">
<input placeholder="˚ #1" id="a-angle">
<br><br>
<input placeholder="X #2" id="b-y">
<input placeholder="Z #2" id="b-x">
<input placeholder="˚ #2" id="b-angle">
<br><br>
<button id="go">go</button>
<pre id="result"></pre>
"use strict"
function tand(deg) {
return Math.tan(deg * Math.PI / 180)
}
function intersect(a, b) {
if (a.slope == b.slope) return false;
var x = (b.intercept - a.intercept) / (a.slope - b.slope)
var y = (a.slope * x) + a.intercept || (b.slope * x) + b.intercept
return {
x: x,
y: y
}
}
function line(point, angle) {
var slope = tand(angle)
var intercept = point.y - (slope * point.x)
return {
slope: slope,
intercept: intercept
}
}
document.querySelector("#go").addEventListener("click", update)
function update() {
var a = line({
x: document.querySelector("#a-x").value,
y: document.querySelector("#a-y").value
}, -1 * document.querySelector("#a-angle").value)
var b = line({
x: document.querySelector("#b-x").value,
y: document.querySelector("#b-y").value
}, -1 * document.querySelector("#b-angle").value)
var result = intersect(a, b)
document.querySelector("#result").textContent = result.y + ", " + result.x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment