/Users/lyon/j4p/src/bookExamples/ch26Graphics/carl/logPolar/PointArray.java

1    package bookExamples.ch26Graphics.carl.logPolar; 
2     
3    /*----------------------------- 
4    class graphics.carl.PointArray.java 
5     
6    October 5, 2001, Carl Weiman 
7     
8    Index Conventions: 
9    ------------------ 
10   Ring (or column) index first  (as x-axis) 
11   Ray (or row)     index second (as y-axis) 
12    
13    
14   ************************************/ 
15    
16   // package mosaics 
17    
18    
19   public class PointArray { 
20    
21       //---------------------- 
22       //  Instance variables | 
23       //---------------------- 
24       private java.awt.geom.Point2D.Float pts[][];    //2D array of points accessible via getter 
25       // where order is: pts[rings][rays] 
26       private float radii[];          // Array of circlet radii, per ring 
27       private java.awt.geom.Point2D.Float origin;     // Coordinate system origin 
28       private float innerRadius;      // radius of inner circle of points 
29       private int ringCount, rayCount;// number of rings, rays 
30       private float expansion;        // Scale factor of expansion per ring 
31    
32       // ------------------ 
33       //  Constructors    | 
34       // ------------------ 
35    
36       //----------------------- 
37       //  General constructor 
38       public PointArray(int _rings, int _rays, java.awt.geom.Point2D.Float _origin, float _radius) { 
39           float x, y; // Computation coordinates 
40           ringCount = _rings; 
41           rayCount = _rays; 
42           origin = _origin; 
43           innerRadius = _radius; 
44    
45           pts = new java.awt.geom.Point2D.Float[ringCount][rayCount]; 
46           radii = new float[ringCount]; 
47    
48    
49           float f_PIrays = (float) Math.PI / (float) rayCount;    // (2*PI/rayCount) 
50           float f_2PIrays = 2f * f_PIrays; 
51    
52           expansion = (float) Math.exp(f_2PIrays);                    // exp(above) 
53    
54           radii[0] = (float) (innerRadius * Math.sin(f_PIrays)); 
55           for (int i_ring = 1; i_ring < ringCount; i_ring++) { 
56               radii[i_ring] = radii[i_ring - 1] * expansion; 
57           } 
58    
59    
60           //---------------------------------------------------- 
61           // Populate a ray at a time, rings outward on each ray 
62           for (int i_ray = 0; i_ray < rayCount; i_ray++) { 
63               processRay(i_ray, f_2PIrays); 
64    
65           } // End of ray for-loop 
66    
67       } // End of general constructor 
68    
69       private void processRay(int i_ray, float f_2PIrays) { 
70           float x; 
71           float y; 
72           x = innerRadius * (float) Math.cos(i_ray * f_2PIrays); 
73           y = -1 * innerRadius * (float) Math.sin(i_ray * f_2PIrays);//Cartesian y coord 
74           pts[0][i_ray] = new java.awt.geom.Point2D.Float(x + origin.x, y + origin.y); 
75           // Construct magnified images of each so-found to populate rings: 
76           processRing(x, y, i_ray); 
77       } 
78    
79       private void processRing(float x, float y, int i_ray) { 
80           for (int i = 1; i < ringCount; i++) { 
81               x *= expansion; 
82               y *= expansion; 
83               pts[i][i_ray] = new java.awt.geom.Point2D.Float(x + origin.x, y + origin.y); 
84           } // End of ring for-loop 
85       } 
86    
87       //---------------------------------------- 
88       //  Default constructor takes no arguments 
89       //      16 ringCount, 48 rayCount 
90       //      origin (100f,100f), innerRadius 100f 
91       public PointArray() { 
92           this(16, 48, new java.awt.geom.Point2D.Float(100f, 100f), 10f); 
93       } 
94    
95       // -------------------------------------- 
96       //  Getters (No setters, use general constructor) 
97       //--------------------------------------- 
98    
99       public java.awt.geom.Point2D.Float[][] get_points() { 
100          return pts; 
101      } 
102   
103      public int get_rayCount() { 
104          return rayCount; 
105      } 
106   
107      public int get_ringCount() { 
108          return ringCount; 
109      } 
110   
111      public float get_innerRadius() { 
112          return innerRadius; 
113      } 
114   
115      public java.awt.geom.Point2D.Float get_origin() { 
116          return origin; 
117      } 
118   
119      public float get_expansion() { 
120          return expansion; 
121      } 
122   
123      public String points_toString() { 
124          String str = ""; 
125          for (int i_ring = 0; i_ring < ringCount; i_ring++) { 
126              for (int i_ray = 0; i_ring < ringCount; i_ring++) { 
127                  str += "\n  r = " + radii[i_ring] + pts[i_ring][i_ray]; 
128              } 
129          } 
130          return (str); 
131      } 
132   
133      public String toString() { 
134          String str; 
135          str = "\n rays: " + rayCount + "; rings: " + ringCount; 
136          str += "\n radius: " + innerRadius; 
137          str += "\n origin: " + origin.toString(); 
138          str += "\n expansion: " + expansion; 
139          return str; 
140      } 
141   
142      //-------------------------------------- 
143      // main method for testing purposes only 
144      //-------------------------------------- 
145      public static void main(String args[]) { 
146          PointArray lppa = new PointArray(3, 4, new java.awt.geom.Point2D.Float(100f, 100f), 100f); 
147          System.out.println(lppa.points_toString()); 
148          System.out.println(lppa.toString()); 
149      } // End of main 
150   
151      public java.awt.geom.Point2D.Float[][] getPts() { 
152          return pts; 
153      } 
154   
155      public void setPts(java.awt.geom.Point2D.Float[][] pts) { 
156          this.pts = pts; 
157      } 
158   
159      public float[] getRadii() { 
160          return radii; 
161      } 
162   
163      public void setRadii(float[] radii) { 
164          this.radii = radii; 
165      } 
166   
167      public java.awt.geom.Point2D.Float getOrigin() { 
168          return origin; 
169      } 
170   
171      public void setOrigin(java.awt.geom.Point2D.Float origin) { 
172          this.origin = origin; 
173      } 
174   
175      public float getInnerRadius() { 
176          return innerRadius; 
177      } 
178   
179      public void setInnerRadius(float innerRadius) { 
180          this.innerRadius = innerRadius; 
181      } 
182   
183      public int getRingCount() { 
184          return ringCount; 
185      } 
186   
187      public void setRingCount(int ringCount) { 
188          this.ringCount = ringCount; 
189      } 
190   
191      public int getRayCount() { 
192          return rayCount; 
193      } 
194   
195      public void setRayCount(int rayCount) { 
196          this.rayCount = rayCount; 
197      } 
198   
199      public float getExpansion() { 
200          return expansion; 
201      } 
202   
203      public void setExpansion(float expansion) { 
204          this.expansion = expansion; 
205      } 
206   
207  }