aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin/AngleTest.kt
blob: ac280404c0477414568104d01d4d00826fdbdc30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
 * Firmament is a Hypixel Skyblock mod for modern Minecraft versions
 * Copyright (C) 2023 Linnea Gräf
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

import kotlin.math.atan

private fun calculateAngleFromOffsets(xOffset: Double, zOffset: Double): Double {
    var angleX = Math.toDegrees(Math.acos(xOffset / 0.04f))
    var angleZ = Math.toDegrees(Math.asin(zOffset / 0.04f))
    if (xOffset < 0) {
        angleZ = 180 - angleZ
    }
    if (zOffset < 0) {
        angleX = 360 - angleX
    }
    angleX %= 360.0
    angleZ %= 360.0
    if (angleX < 0) angleX += 360.0
    if (angleZ < 0) angleZ += 360.0
    var dist = angleX - angleZ
    if (dist < -180) dist += 360.0
    if (dist > 180) dist -= 360.0
    return angleZ + dist / 2
}

fun main() {
    for(i in 0..10) {
        for (j in 0..10) {
            println("${calculateAngleFromOffsets(i.toDouble(),j.toDouble())} ${atan(i.toDouble() / j.toDouble())}")
        }
    }
}