#Trigonometry
1 messages · Page 1 of 1 (latest)
so you know the coords of the point and the location of the player
imagine building a right triangle with the hypothenuse being the segment between the player and the point
you need to get the angle between the hypothenuse and one of the sides of the triangle
Will reiterate; I have a BukkitRunnable that will iterate over the players in the game and I intend on having a Set of players (so no duplicates) where whenever a player has their line of sight towards the ability activator with a configurable offset, they will be added to the set, it will then force everyone in the set to look at the activator until the ability ends
so any player in the Set have to look at a point for a while
Yeah that's right, in which case that point might change (if the activator moves)
with need to i mean the plugin has to force them to
Yeah, I know I'll have to somehow calculate the yaw/pitch to use and just constantly teleport them to their same x/y/z cords (as I want them to be able to move still)
ok so imagine the blue dot is the player and the red one is the activator
you need to get alpha (yellow angle)
right?
by definition, sin(alpha) = side of the triangle opposing the angle / hypothenuse
in this case the side opposing alpha is the shortest one
and the hypothenuse is the distance between the player and the point
Yeah, I already have a formula to work out the hypothenuse
you can just call .distance from Location
Oh, guess I just recreated that for no reason then lol but anyway
i'd suggest using distanceSquared since computing a square root is expensive
since the distance you calculate with pythagoras' theorem
which i guess you know
Yeah
so basically you can get the distance squared by running a^2 + b^2
and not computing the sqrt
because it's expensive
and to compensate you square the other side too (the height of the triangle)
do you know the 3 theorems of similar triangles? (not sure of the english name)
In that case on another note, if I wanted to see if a player is within the radius of a location, would it work and be most efficient to compare distanceSquared vs radius^2?
That's good to know, thank you. Now how can we use distance squared to get the yaw and pitch?
.
basically you can extrapolate from them that if you square all of the sides of the triangle, the angles don't change
so we can compute the sin without having to use sqrt
so we can do sin(alpha) = height^2 / distance^2
then if you compute the asin of that value, you get the angle
So I should manually calculate the hypotenuse of the angle and disregard y then calculate the hypotenuse again after knowing the angle?
no, you need to calculate the distance (which you have)
and the height (which is the difference between the x values of the coords)
So I'd get 1 of the angles from the sin of the (difference in y)^2 / distance^2 then the other angle from the difference in x^2/ distance^2?
i'm talking about 2 dimensions still here so try that first
then yea i think that could work
what the fuckius
trigonometry
Knew I should've paid more attention in school
I enjoyed algebra and solving problems but always sucked at both geometry and trigonometry
I don't blame you for sucking at geometry
anyways try to implement that code in a command or something and broadcast the outcome to see if the math is correct
also remember that trigo functions in java use radians
not degrees
i'll go code, ping me if u need any help
Okay I'll just send you a message if it doesn't work 😁 thanks