Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple Rectangle2D/geometry issue

Steffen Reinhard
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hio all!

Having browsed the topic list I feel a bit shy to ask a - presumably - rather silly question, but I really haven't any clue how it could be done.

Dramatis personae: An applet graphics-object cast to a Graphics2D object within body of paint() method, a Rectangle 2D.Double, filled and painted, a couple of GeneralPaths initialized to start from a given location (using AffineTransform.getTranslateInstance(500,300)).

How can I draw a couple of lines (moving from the given 0,0 coordinates and bouncing off the drawn rectangle), thus eventually filling up the whole Rectangle2D surface.

As far as I figured out, I can use the Rectangle2D's outcode() method(s) to check if a given Point2D p lies within the Rectangle returning outcode 0) or not (returning outcodes 1 to 12, respectively).

I can even figure out the position of given point relative to the given Rectangle2D (using the return value of Rectangle2D's outcode methods).

What I didn't manage to do so far is
  • calculate Coordinates of Point2D to append to GeneralPath after bouncing off the Rectangle2D's border (that is: calculate the change of direction)
  • animate the whole thing without getting chatty error messages

  • Now, I hope I haven't asked an exceedingly 'off-topic' question, but I just can't figure out how to do it.

    Thanks in advance for any suggestions!

    Cheers -

    [ August 01, 2005: Message edited by: Steffen Reinhard ]
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic