hi i'm new to scratch, i have a question, if there is 3 sprite A,B(my own sprite),and C(random sprite that is moving randomly) if sprite A is stable and sprite B and C is always moving will i be able to figure out the angle of which i can move to find sprite C using cosine law?
for the distance to spriteX means the distance from sprite B to X
let D2=distance from sprite C to B
example: distance of sprite C * distance of sprite C - D2 * D2 - distance of B * distance of B/ 2*distance of sprite C * D2 inverse cosine C
i'm not sure if that make sense or work so i was wondering, is there a way where i can use the cosine law to figure out the angle so that my sprite B can always move toward sprite C?
thanks i know its kinda complicated, but i just really want to know if there is a way of doing it using trig. triangulation method
thanks!
Offline
I beleive you would want to use Tan rather than Cos, since in trig terms the difference in Y will be the Opposite and the difference in X will be the Adjacent.
Tan of angle = Opposite/Adjacent.
However, you will need extra code to translate that into a scratch direction, to make sure it is applying the angle in the correct direction - ie measuring clockwise from vertical instead of anticlockwise, and measuring from the zero point and not the 180 degree point.
Offline
deerel wrote:
scratchrulesOMG wrote:
... to figure out the angle so that my sprite B can always move toward sprite C?
Use this:
<point towards( C
The Point Towards block is very useful in this case.
Offline
Mayhem wrote:
I beleive you would want to use Tan rather than Cos, since in trig terms the difference in Y will be the Opposite and the difference in X will be the Adjacent.
Tan of angle = Opposite/Adjacent.
However, you will need extra code to translate that into a scratch direction, to make sure it is applying the angle in the correct direction - ie measuring clockwise from vertical instead of anticlockwise, and measuring from the zero point and not the 180 degree point.
Tan? is there such thing as a tan rule? and how would i be able to do that if i use tan? has anyone tried this out before?
and i don't really want to use the point towards tool cause thats just too easy i want to try something harder to see if its possible
Offline
scratchrulesOMG wrote:
Mayhem wrote:
I beleive you would want to use Tan rather than Cos, since in trig terms the difference in Y will be the Opposite and the difference in X will be the Adjacent.
Tan of angle = Opposite/Adjacent.
However, you will need extra code to translate that into a scratch direction, to make sure it is applying the angle in the correct direction - ie measuring clockwise from vertical instead of anticlockwise, and measuring from the zero point and not the 180 degree point.Tan? is there such thing as a tan rule? and how would i be able to do that if i use tan? has anyone tried this out before?
and i don't really want to use the point towards tool cause thats just too easy i want to try something harder to see if its possible
A TON of trig needed for that. The easiest way ('cause I don't know trig) I know is this: http://scratch.mit.edu/projects/halfbaked_fullmoon/336029
Offline
is there a way of finding another sprites x,y position without using the x/y position of the sprite? like using trig?
Offline
scratchrulesOMG wrote:
Tan? is there such thing as a tan rule? and how would i be able to do that if i use tan? has anyone tried this out before?
Here you go.
http://scratch.mit.edu/projects/Mayhem/340819
Offline
scratchrulesOMG wrote:
is there a way of finding another sprites x,y position without using the x/y position of the sprite? like using trig?
Yes, but to do it with trig you would need the "point towards" and "distance" tools
Offline
http://scratch.mit.edu/projects/scratchrulesOMG/341702
this shows the codes that i did i'm not sure if i done somethign wrong, all i did is applied the cosine law so i'm not sure if thats right, is there more trig to it? or?
please help
thank you very much!
Offline