Computing heading

Andreas Raab andreas.raab at
Sun Jan 4 22:41:11 UTC 2004

[Second reply in this thread - the first one was rejected by the list
moderator with "No reason given". It included a project (117k) which
illustrated the point below].

> EToys doesn't have to use coordinates....  You can tell a morph to point
> to another morph.
> Hmm, actually, you can't do that exactly.  But you can tell a morph to
> *move toward* another morph.  So try moving it to right place, telling
> it to move toward the other morph, and then moving it back to the right
> place again.

Here's another way of doing it: Just make up a morph which represents the
angle (e.g., set its x/y to the difference of the guys being tracked) and
use its "theta" to find out what the angle is.

The only problem you have is that theta, contrary to (I think all) other
angular measures goes ccw instead of cw and therefore the x/y needs to be
computed as
    Angle's x <- Destination's x - Source's x.
    Angle's y <- Source's y - Destination's y.
(swapping the y-computation above does the trick for turning theta to cw but
understanding why and proving that this works is an interesting little
exercise ;-)

Once you've done the above Angle's theta will hand you the required
heading-90 since (unfortunately) theta is measured against the positive
x-axis but heading is measured against the positive y-axis, so one would
need to do something like

    Arrow's heading <- Angle's theta + 90.

And finally, you can put Angle into a playfield with "origin-at-center" and
normalize the display using the "distance" property so you can actually see
it moving. The project I had originally attached demonstrated this quite

  - Andreas

More information about the Squeak-dev mailing list