Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:04:35+00:00 2026-06-17T09:04:35+00:00

I have an interesting problem. Using Java graphics, I’d like to draw a circle

  • 0

I have an interesting problem. Using Java graphics, I’d like to draw a circle with parallel lines in the circle that are spaced with some pre defined gap constant. The circle has a known x and y position and a radius. The lines should start from the center of the circle and should move outward thereof. For example,

enter image description here

I’d imaging it would be easiest to first draw the lines to fill up the whole square as follows:

enter image description here

and then perhaps draw 4 polygons and fill them in white white. The 4 polygons are labeled as follows:

enter image description here

As you can see, a polygon in this case is defined by a left top point (x,y), edges of width and height defined by the radius of the circle, and then an arc from (x+radius, y+radius).

Feedback needed:

  1. Is it even possible to draw such a polygon in Java?
  2. Is this logic making sense? Does this seem easier to you?
  3. The alternative is to somehow determine the pixels that make up the circle and draw lines using those. But this seems messy to me. Do you agree?
  4. Can you think of an alternative way of doing this?

IMPORTANT: note that while this solution has vertical lines, the lines should be defined in terms of some angle theta. That is, they can be angled (but all parallel to each other).

If someone could provide code that actually draws this, I would be forever thankful!! 🙂

public void draw(Graphics g, int x, int y, int radius, int lineGap, int lineThickness, int theta) {
   //g = the graphics object
   //x,y = the top left coordinate of the square
   //radius = the radius of the circle, the width of the rectangle, the height of the rectangle
   //lineGap = the gap in between each of the lines
   //lineThickness = the thickness of the lines in pixels
   //theta = the angle that the lines should be at, relative to the y axis
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:04:35+00:00Added an answer on June 17, 2026 at 9:04 am

    Simple change the graphics clipping…

    enter image description here

    public class SimplePaint02 {
    
        public static void main(String[] args) {
            new SimplePaint02();
        }
    
        public SimplePaint02() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    }
    
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(new TestPane());
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    
        public class TestPane extends JPanel {
    
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(100, 100);
            }
    
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
    
                int radius = Math.min(getWidth(), getHeight());
                int x = (getWidth() - radius) / 2;
                int y = (getHeight()- radius) / 2;
    
                BufferedImage buffer = new BufferedImage(radius, radius, BufferedImage.TYPE_INT_ARGB);
                Graphics2D g2d = buffer.createGraphics();
    
                Ellipse2D circle = new Ellipse2D.Float(0, 0, radius, radius);
                Shape clip = g2d.getClip();
                g2d.setClip(circle);
                int gap = getWidth() / 10;
                g2d.setColor(Color.RED);
                for (int index = 0; index < 10; index++) {
    
                    g2d.drawLine(index * gap, 0, index * gap, radius);
    
                }
                g2d.setClip(clip);
                g2d.setColor(Color.BLUE);
                g2d.draw(circle);
                g2d.dispose();
                g.drawImage(buffer, x, y, this);
            }
    
        }
    
    }
    

    Update

    I should point out that you should NEVER modify any graphics context’s clipping that is rendering to the screen, this can seriously screw up the screen rendering 😉

    Updated #2

    Example showing the use of an AffinTransformation to support rotation…

    enter image description here

    public class CirlceDraw {
    
        public static void main(String[] args) {
            new CirlceDraw();
        }
    
        public CirlceDraw() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    }
    
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(new TestPane());
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
    
            });
        }
    
        public class TestPane extends JPanel {
    
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(100, 100);
            }
    
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
    
                int radius = Math.min(getWidth(), getHeight());
                int x = (getWidth() - radius) / 2;
                int y = (getHeight() - radius) / 2;
    
                BufferedImage buffer = new BufferedImage(radius, radius, BufferedImage.TYPE_INT_ARGB);
                Graphics2D g2d = buffer.createGraphics();
    
                Ellipse2D circle = new Ellipse2D.Float(0, 0, radius, radius);
                Shape clip = g2d.getClip();
                g2d.setClip(circle);
                AffineTransform at = g2d.getTransform();
                g2d.setTransform(AffineTransform.getRotateInstance(Math.toRadians(33), radius / 2, radius / 2));
                int gap = getWidth() / 10;
                g2d.setColor(Color.RED);
                for (int index = 0; index < 10; index++) {
    
                    g2d.drawLine(index * gap, 0, index * gap, radius);
    
                }
                g2d.setTransform(at);
                g2d.setClip(clip);
                g2d.setColor(Color.BLUE);
                g2d.draw(circle);
                g2d.dispose();
                g.drawImage(buffer, x, y, this);
            }
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting problem when using partial page update in asp.net with scriptmanager
We have an interesting problem with WCF binding and streaming transfer mode that we
I have some interesting problem for an hour.. In my flex project, all width
I have an interesting problem. The basis of the problem is that my last
I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
I have an interesting problem with hibernate, the model looks like the following: @NamedQueries({
We have rather large code base (150+ projects, 400000+ lines of Java code, some
I have an interesting problem. I'm using visual basic and before saving a row
I have an interesting problem. I am using Ant which executes JUnit tests (test
I have an interesting problem that i can't seem to figure out. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.