I think you'll need to post an image of the problem and what is required.
All truths are easy to understand once they are discovered; the point is to discover them...
G. Galilie
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Here is an example of concentric ellipses. using the Java Ellipse or java Arc function, and varying the size of the ellipse (StartX, StartY w, h, start angle and end angle) to account fo rthe gap between the ellipses, we will get concentric ellipses, which are not parallel!
As you see in the attached image the Ellipses are not Parallel, they are concentric. What I am looking for is a way to draw 2 Parallel Arcs where the distance between the arcs remain constant along the entire Arc. If the Arcs are that of a circle, the line are indeed Parallel, but as elliptical arcs, they are not. I found some documentation stating that one has to draw and Oval parallel to the Arc/Ellipse but in Java, I cannot find a way to do this, as there is only arc2D to work with.
If you want parallel ellipses then you just reduce the width and height by the same amount. for example:
Code:
public void paintComponent(Graphics g)
{
// draw concentric non-parallel ellipses
for( int i = 30; i <= 70; i += 10)
{
int w = i * 2;
int h = i;
g.drawArc(100-(w/2), 50-(h/2), w, h, 0, 360);
}
// draw concentric parallel ellipses
for( int i = 30; i <= 70; i += 10)
{
int w = 50 + i;
int h = i;
g.drawArc(300-(w/2), 50-(h/2), w, h, 0, 360);
}
}
If you make the h=1/3; and run the parallel ellipses code, you will see what i mean. As long as the H and W are close in dimensions, you do not actually see the error, i.e. the error goes away as you approach a circle where h=w.
Last edited by sherif6; May 6th, 2010 at 05:54 AM.
The code I provided earlier and amended here appears to draw parallel ellipses (within the pixelisation limits of the screen). You need to provide a simple code example that produces the problem you are seeing or explain what is wrong with the image shown
Code:
public class ScratchPad extends JPanel
{
@Override
public void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
// draw concentric non-parallel ellipses
for( int i = 30; i <= 70; i += 6)
{
int w = i * 2;
int h = i;
g.drawArc(100-(w/2), 50-(h/2), w, h, 0, 360);
}
// draw concentric parallel ellipses
for( int i = 30; i <= 70; i += 6)
{
int w = 90 + i;
int h = i;
g.drawArc(300-(w/2), 50-(h/2), w, h, 0, 360);
}
// draw concentric parallel ellipses
for( int i = 30; i <= 70; i += 6)
{
int w = 90 + i;
int h = i;
Arc2D shape = new Arc2D.Double(100-(w/2), 150-(h/2), w, h, 0, 180, Arc2D.OPEN);
((Graphics2D)g).draw(shape);
}
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch ( Exception e )
{
System.out.println("Failed to set Look and Feel.\n"+e);
}
JFrame frame = new JFrame("Ellipse Tester");
frame.add(new ScratchPad());
frame.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension d = frame.getSize();
d.width += 300;
d.height += 300;
frame.setSize(d);
frame.setLocation((screenSize.width-d.width)/2, (screenSize.height-d.height)/2);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
The top left image is the non parallel ellipses, the top right image is the parallel ellipses and the bottom left image is the parallel arcs. Remember a pixel isn't necessarily square, it's width to height ratio depends on the aspect ratio of your screen and the resolution you are displaying at.
The shapes drawn using the w and h presented are not Ellipse but Ovals in that they do not satisfy the standard elliptical equation. x^2/a^2 + y^2/b^2 = 1.
so to actually draw a Curve parallel to an ellipse there need to be a way to put a perpendicular line of a specific size (the distance between the 2 ellipse), calculate the x,y coordinates of the end of that line, then plot all those points to finally get a parallel curve.... or at least that is my take on it.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.