![]() |
| ||
| Drawing a spiral Ok, so my goal is to draw a rectangular spiral in java. So far, I've created the Spiral Viewer class and the SpiralComponent but I'm not quite sure how I would implement the SpiralGenerator class. Here's what I have: SpiralViewer: import javax.swing.JFrame; SpiralComponent: import javax.swing.JComponent; Spiral Generator: import java.awt.geom.Point2D; SpiralTester: import java.awt.geom.Point2D; |
| ||
| Re: Drawing a spiral There are two different ways you can approach drawing the spiral. 1) Using GeneralPath to define the path from a fixed coordinate system in which you define the coordinates of the segments to be drawn on a fixed x-y plane. 2) Using coordinate transformations (translate, rotate) to alter the coodinate system as you draw each segment. With translation and rotation, drawing the path becomes trivial. You simply draw a line in a fixed direction (which ever way you want to go from your origin, like 0,0 to 0,100, translate to the end of that line, rotate 90 deg left or right, draw a slightly shorter line in the same direction as the first (perhaps 0,0 to 0,90), and continue until you reach the endpoint you want. By moving and rotating your origin as you draw, you only have to draw increasingly shorter line segments in the direction of path traversal. There are some examples of using coordinate transforms here: http://www.java2s.com/Code/Java/2D-G...ndRotation.htm Hope that helps get you started. |
| ||
| Re: Drawing a spiral Heya, thanks for the reply but I already finished it =P. |
| All times are GMT -4. The time now is 4:28 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC