Hi Everyone,
How can I make sure the following shapes are centered around (0,0)?
I have tried various combinations but they still appear off centered
when I plot them in a chart.
private Shape generateShape(int aColorIndex)
{
double lScale = 10;
double lDelta = .5 * lScale;
int lIndex = aColorIndex % 10;
int[] lXPoints = null;
int[] lYPoints = null;
int lXPoint = 0;
int lYPoint = 0;
switch (lIndex)
{
case 0:
// Square
return new Rectangle2D.Double(0,0,lScale, lScale);
case 1:
// Circle
return new Ellipse2D.Double(0,0,lScale, lScale);
case 2:
// Up-pointing triangle
lXPoints = intArray(lXPoint, lXPoint + lDelta, lXPoint - lDelta);
lYPoints = intArray(lYPoint- lDelta, lYPoint + lDelta, lYPoint + lDelta);
return new Polygon(lXPoints, lYPoints, 3);
case 3:
// Diamond
lXPoints = intArray(lXPoint, lXPoint + lDelta, lXPoint , lXPoint - lDelta);
lYPoints = intArray(lYPoint - lDelta, lYPoint, lYPoint + lDelta, lYPoint);
return new Polygon(lXPoints, lYPoints, 4);
case 4:
// Horizontal rectangle
return new Rectangle2D.Double(lXPoint - lDelta, lYPoint - lDelta / 2, lScale, lScale / 2);
case 5:
// Down-pointing triangle
lXPoints = intArray(lXPoint - lDelta, lXPoint + lDelta, lXPoint);
lYPoints = intArray(lYPoint - lDelta, lYPoint - lDelta, lYPoint + lDelta);
return new Polygon(lXPoints, lYPoints, 3);
case 6:
// Horizontal ellipse
return new Ellipse2D.Double(lXPoint - lDelta, lYPoint - lDelta / 2, lScale, lScale / 2);
case 7:
// Right-pointing triangle
lXPoints = intArray(lXPoint - lDelta, lXPoint + lDelta, lXPoint - lDelta);
lYPoints = intArray(lYPoint - lDelta, lYPoint , lYPoint + lDelta);
return new Polygon(lXPoints, lYPoints, 3);
case 8:
// Vertical rectangle
return new Rectangle2D.Double(lXPoint - lDelta / 2, lYPoint - lDelta, lScale / 2, lScale);
default:
// Vertical ellipse
return new Ellipse2D.Double(lXPoint - lDelta / 2, lYPoint - lDelta, lScale / 2, lScale);
}
}
Centering Shapes?
Re: Centering Shapes?
Hi Alex,
The Shape objects that you create should have their centres at (0, 0), because JFreeChart just translates the coordinates to (x, y) as required.
For example, to create a square 6 units across:
return new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0);
Regards,
Dave Gilbert
The Shape objects that you create should have their centres at (0, 0), because JFreeChart just translates the coordinates to (x, y) as required.
For example, to create a square 6 units across:
return new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0);
Regards,
Dave Gilbert
Re: Centering Shapes?
Thanks David I don't know what I was thinking....
As always your help is greatly appreciated!!!
Alex
As always your help is greatly appreciated!!!
Alex