Click to See Complete Forum and Search --> : How to Draw 2 parallel Elliptical Arc?


sherif6
May 5th, 2010, 04:17 AM
I am stuck. 2 Concentric Elliptical arc are not parallel... How to get them to be parallel?

dlorde
May 5th, 2010, 04:26 AM
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

sherif6
May 5th, 2010, 03:09 PM
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!

sherif6
May 5th, 2010, 03:45 PM
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.

keang
May 5th, 2010, 04:01 PM
If you want parallel ellipses then you just reduce the width and height by the same amount. for example:
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);
}
}

sherif6
May 5th, 2010, 04:53 PM
That was my original thought. But it does not work. The resulting arcs are NOT parallel!!!!!

this.myParent.myElevation.append(
(new Arc2D.Double(this.top1.bkgrdStartX,
this.top1.bkgrdStartY,
this.top1.bkgrdWidth,
this.top1.bkgrdHeight,
this.top1.startAngle, this.top1.endAngle,Arc2D.OPEN)),false);

followed by :

this.myParent.myElevation.append(
(new Arc2D.Double(this.top1.bkgrdStartXBA,
this.top1.bkgrdStartYBA,
this.top1.bkgrdWidthBA,
this.top1.bkgrdHeightBA,
this.top1.startAngleBA, this.top1.endAngleBA,Arc2D.OPEN)),false);

where:
bkgrdStartXBA = bkgrdStartX - 20
bkgrdStartYBA = bkgrdStartY + 20
bkgrdWidthBA = bkgrdWidth - 40
bkgrdHeightBA = bkgrdHeight - 40

startAngleBA = startAngle = 0
endAngleBA = endAngle =180

sherif6
May 5th, 2010, 11:16 PM
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.

keang
May 6th, 2010, 08:22 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

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.

sherif6
May 6th, 2010, 03:07 PM
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.

http://mathforum.org/library/drmath/view/71782.html

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.

Or do it using this formula http://mathworld.wolfram.com/ParallelCurves.html which I do not know how to do!