I need to calculate an arc for a small paint program in director. It will be a constant 90 degrees between two mouse clicks and should be "right side up" or "up side down" if the last click was higher or lower than the first. Then it needs to be draw to the bitmap castmember.


Well, that was a nice mental exercise! Try this:

http://staff.funnygarbage.com/colin/arc.dir

When you start the movie, it doesn't work the way you asked for. Instead it makes an arc based on the first and second clicks regardless of their screen position. Try making what is roughly a circle by clicking at the 6 o'clock position, then 3, then 3, then 12, then 12, then 9, then 9, then 6 again. You should get a rough circle, which I think would the nicer way to work. You can go the other way around, starting with 3 o'clock, then 6, and so on.

If you option(alt) click at any time, it will toggle to the way that you asked it to work, and then the arc will be curved based on which of the two clicks was further up the screen. It becomes a lot more difficult to do something nice.

The file is a DIR, so you can open it from within Director 8.5 or MX, just go to File/Open and choose Internet and paste in the URL.

For anyone not that desperate to know how it's working (enough to look at the DIR), the interesting part of the problem was working out where the center of the circle is located. The drawing the arc is pretty straight forward.

What we know about the two points is that they are on the same circle, and are 90 degrees away from each other. In this case we don't need to bother with degrees, because 90 degrees is half pi, which means we can just calculate using pi, and then things like sin() and cos() are happier.

To work out where the center of the circle is, you need to know the direction of the center from one of the points, and you need to know the radius of the circle. As the angle at the center to the two points is half pi, that means that the angle between the direction of the other point and the center is quarter pi.

If p1 and p2 are the points, you know the angle between them using atan(), and so the angle from the center would be that - three quarters of pi:

  dx = p2[1]-p1[1]
  dy = p2[2]-p1[2]
  angletocenter = atan(dx,dy) - pi*.75

The triangle that forms the center and the two points has two sides the same length, which means that we can use Pythagoras to work out the length of one of the short sides (which will be the radius of the circle):

distancetocenter = sqrt((dx*dx+dy*dy)*.5)

To work out where the center is, we subtract the point that the center is relative to the starting point, from the starting point:

centerpoint = p1 - point(sin(angletocenter)*distancetocenter,cos(angletocenter)*distancetocenter)


That gives a center to then draw the arc, which will start at the angletocenter and end a half pi later. You can look at the movie for the drawing routine.


My demo movie has a bitmap that is the size of the stage, so there may be other things to solve to make the bitmap be any size on the stage, but you're welcome to deal with that part!

[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]

Reply via email to