Computing heading

Bert Freudenberg bert at
Sun Jan 4 13:26:34 UTC 2004

Am 04.01.2004 um 09:41 schrieb Jack Johnson:

> I was messing around with EToys and grabbed an arrow morph and a 
> couple of ellipses and wanted to have the arrow morph automatically 
> place itself between the two ellipses and point from one to the other.
> The placement was easy, but I had trouble computing the heading.

Doing math with EToys is not as easy as we wish sometimes ... but 
Squeak provides almost everything you'll ever need. The method you are 
looking for probably is Point>>bearingToPoint:. It's just a bit odd how 
to get that into your EToy. Here is one way:

I called my two ellipses Red and Yellow, and got an Arrow from the 
Object Catalogue. You need to rotate the Arrow once with the halo and 
make its forwardDirection (the tiny green arrow) match its actual 
direction. After creating a "move" script for Arrow which places it 
between the two ellipses, I made a "rotate" script for Arrow like this:

	Arrow's heading <- Yellow's heading + Red's heading

This is only to get references to both ellipses into the script. Now 
you can switch the script to text mode (the checkbox near the 
upper-left corner). You see Smalltalk similar to this:

		self setHeading: Yellow1 getHeading + Red1 getHeading

I edited this script to use the #bearingToPoint: method (press Meta-S 
to save):

		self setHeading: (Yellow1 costume center bearingToPoint: Red1 costume 

It uses the ellipses' costumes directly because they provide the 
#center method - EToy itself does not support Points, only Numbers like 
x and y.

And that's about it. You can browse the implementation of 
#bearingToPoint: to see the formula used. I'll attach my own project as 
an example.

- Bert -

-------------- next part --------------
A non-text attachment was scrubbed...
Type: application/octet-stream
Size: 64563 bytes
Desc: not available
Url :
-------------- next part --------------

More information about the Squeak-dev mailing list