This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-12-03 03:01:23

scratchrulesOMG
Scratcher
Registered: 2008-12-03
Posts: 14

Trig. Triangulation help

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

 

#2 2008-12-03 04:14:00

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Trig. Triangulation help

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.


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#3 2008-12-03 04:39:13

deerel
Scratcher
Registered: 2008-08-23
Posts: 89

Re: Trig. Triangulation help

scratchrulesOMG wrote:

... to figure out the angle so that my sprite B can always move toward sprite C?

Use this:
<point towards( C

Offline

 

#4 2008-12-03 06:14:52

bhz
Scratcher
Registered: 2008-07-06
Posts: 100+

Re: Trig. Triangulation help

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

 

#5 2008-12-03 19:30:07

scratchrulesOMG
Scratcher
Registered: 2008-12-03
Posts: 14

Re: Trig. Triangulation help

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

 

#6 2008-12-03 19:57:37

bhz
Scratcher
Registered: 2008-07-06
Posts: 100+

Re: Trig. Triangulation help

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

 

#7 2008-12-03 20:03:51

scratchrulesOMG
Scratcher
Registered: 2008-12-03
Posts: 14

Re: Trig. Triangulation help

is there a way of finding another sprites x,y position without using the x/y position of the sprite? like using trig?

Offline

 

#8 2008-12-04 07:53:18

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Trig. Triangulation help

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


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#9 2008-12-04 07:57:27

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Trig. Triangulation help

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


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#10 2008-12-04 22:07:21

scratchrulesOMG
Scratcher
Registered: 2008-12-03
Posts: 14

Re: Trig. Triangulation help

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

 

Board footer