#Trigonometry

1 messages · Page 1 of 1 (latest)

tawdry creek
#

I suck at trigonometry, help plz c:

eager seal
#

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

tawdry creek
#

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

eager seal
#

so any player in the Set have to look at a point for a while

tawdry creek
#

Yeah that's right, in which case that point might change (if the activator moves)

eager seal
#

with need to i mean the plugin has to force them to

tawdry creek
#

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)

eager seal
#

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

tawdry creek
#

Yeah, I already have a formula to work out the hypothenuse

eager seal
#

you can just call .distance from Location

tawdry creek
#

Oh, guess I just recreated that for no reason then lol but anyway

eager seal
#

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

tawdry creek
#

Yeah

eager seal
#

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)

tawdry creek
#

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?

eager seal
#

yes

#

very noticeable if you need to iterate the Set

#

and execute it often

tawdry creek
#

That's good to know, thank you. Now how can we use distance squared to get the yaw and pitch?

eager seal
#

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

tawdry creek
#

So I should manually calculate the hypotenuse of the angle and disregard y then calculate the hypotenuse again after knowing the angle?

eager seal
#

no, you need to calculate the distance (which you have)

#

and the height (which is the difference between the x values of the coords)

tawdry creek
#

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?

eager seal
#

i'm talking about 2 dimensions still here so try that first

#

then yea i think that could work

copper bolt
#

what the fuckius

eager seal
#

trigonometry

copper bolt
#

I'm too dumb to understand

#

Goodbye

eager seal
#

cya

#

lol

tawdry creek
#

Knew I should've paid more attention in school

#

I enjoyed algebra and solving problems but always sucked at both geometry and trigonometry

eager seal
#

i actually have not studied this stuff in school yet

#

i kinda taught them to myself

copper bolt
eager seal
#

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

tawdry creek