N
N
nuub2282021-07-29 20:41:52
Mathematics
nuub228, 2021-07-29 20:41:52

What algorithm/formula is used in the site?

There is such a site https://www.skrepkaq.ru/stronghold , it searches for a "fortress" from the minecraft game

You need to specify 2 coordinates and the angle where the player is looking, but I can't find out what formula is used in this site

Very interesting, I wanted to make a mini script

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SKEPTIC, 2021-07-29
@smertelny

Everything is easily accessible from js code

const p = Math.PI/180;
function cot(x) { return 1 / Math.tan(x); }
    function getPortalCoords(x1, z1, a1, x2, z2, a2) {
        var a1 = parseFloat(a1),
            a2 = parseFloat(a2),
            x1 = parseInt(x1),
            z1 = parseInt(z1),
            x2 = parseInt(x2),
            z2 = parseInt(z2);
console.log(a1,a2,x1,z1,x2,z2);
if(Math.abs(a1 - a2) < 1) {alert("углы не могут быть равны!")}
    else if ((((a1 < 0) && (a2 > 0)) || ((a1 > 0) && (a2 < 0))) && (Math.abs(Math.abs(Math.abs(a1) - 180) - Math.abs(a2)) < 1)) {alert("углы не могут быть противоположны")}
    else{
      switch(Math.round(a1)) {
        case -180:
        case 0:
        case 180:
          document.getElementById('x-output').value = Math.round(x1);
          document.getElementById('z-output').value = Math.round(cot(-a2*p)*x1 - (x2*cot(-a2*p) - z2));
          break;
        case -90:
        case 90:
          document.getElementById('z-output').value = Math.round(z1);
          document.getElementById('x-output').value = Math.round(Math.round(x2*cot(-a2*p) - z2 + z1)/cot(-a2*p));
          break;
        default:
console.log(1);
          switch(Math.round(a2)){
            case -180:
            case 0:
            case 180:
              document.getElementById('x-output').value = Math.round(x2);
              document.getElementById('z-output').value = Math.round(cot(-a1*p)*x2 - (x1*cot(-a1*p) - z1));
              break;
            case -90:
            case 90:
              document.getElementById('z-output').value = Math.round(z2);
              document.getElementById('x-output').value = Math.round((x1*cot(-a1*p) - z1 + z2)/cot(-a1*p));
              break;
            default:
console.log(2);
              document.getElementById('x-output').value = Math.round(((x1*cot(-a1*p) - z1) - (x2*cot(-a2*p) - z2))/(cot(-a1*p) - cot(-a2*p)));
              document.getElementById('z-output').value = Math.round(cot(-a1*p)*document.getElementById('x-output').value-(x1*cot(-a1*p)-z1));
          }
      }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question