CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2005
    Posts
    6

    Unhappy How to Draw 2 parallel Elliptical Arc?

    I am stuck. 2 Concentric Elliptical arc are not parallel... How to get them to be parallel?

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: How to Draw 2 parallel Elliptical Arc?

    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.

  3. #3
    Join Date
    Aug 2005
    Posts
    6

    Re: How to Draw 2 parallel Elliptical Arc?

    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!
    Attached Images Attached Images

  4. #4
    Join Date
    Aug 2005
    Posts
    6

    Unhappy Re: How to Draw 2 parallel Elliptical Arc?

    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.

  5. #5
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: How to Draw 2 parallel Elliptical Arc?

    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);
            }
        }
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  6. #6
    Join Date
    Aug 2005
    Posts
    6

    Unhappy Re: How to Draw 2 parallel Elliptical Arc?

    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
    Last edited by sherif6; May 5th, 2010 at 05:55 PM.

  7. #7
    Join Date
    Aug 2005
    Posts
    6

    Re: How to Draw 2 parallel Elliptical Arc?

    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.

  8. #8
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: How to Draw 2 parallel Elliptical Arc?

    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.
    Attached Images Attached Images
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  9. #9
    Join Date
    Aug 2005
    Posts
    6

    Re: How to Draw 2 parallel Elliptical Arc?

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured