Results 1 to 8 of 8
  1. #1
    Veronica91 is offline Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Default Center point of Circle

    Hi I'm a little confused. By default, if talking about a circle in Java, is the location of x, y at the top left corner of a bounding box? If i were to simply get the width of a circle and divide it by two, would that give me the center point? If the width is taken from top left corner to bottom right corner then I believe that would work. However if the width is taken from top left corner to top right corner for example, that wouldn't give the center point. The Processing language lets a user change from the default top left to a center point using 'ellipseMode(CENTER)'. Just curious about that, but I would like to know how I can find the center point of a circle 'manually' in java.

    I was trying something like below, considering the width point is taken from top left to top right but I still don't think this would work.

    Java Code:
    		float playerCenterX = ((playerObject.getX()) + (playerObject.getWidth()/2)); 
    		playerObject.setY(playerCenterX); 
    		float playerCenterY = ((playerObject.getY() + playerObject.getWidth()/2));

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Center point of Circle

    What circle though?
    How is the circle defined?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Veronica91 is offline Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Default Re: Center point of Circle

    I believe it is defined in the below code? Sorry I'm too sure as I didn't write it. Its all located in a separate class named GameObject. The game displays random sized circles and positions at the start of each run. Btw this is part of an assignment where one task was to develop a method for collision detection. That's what my OP was about.

    Hope this helps.

    Java Code:
    public void draw()
    	{
    		// draw quad
    		GL11.glPushMatrix();
    			GL11.glColor3f(r_, g_, b_);
    			GL11.glTranslatef(x_, y_, 0);
    			GL11.glScalef(width_/2, width_/2, 1);
    			GL11.glBegin(GL11.GL_TRIANGLE_FAN);
    			GL11.glVertex2f(0, 0);
    			for(int i = 0; i <= 50; i++){
    			    double angle = Math.PI * 2 * i / 50;
    			    GL11.glVertex2f((float)Math.cos(angle), (float)Math.sin(angle));
    			}
    			GL11.glEnd();
    		GL11.glPopMatrix();
    	}

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Center point of Circle

    What is GL11?
    That doesn't look like a core Java class.
    The first thing you need to do is find out what framework you are working with.
    I'm going to guess at JOGL...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Center point of Circle

    Nope, looks like it's libgdx.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Veronica91 is offline Member
    Join Date
    Sep 2012
    Posts
    9
    Rep Power
    0

    Default Re: Center point of Circle

    Its using LWJGL.

    I found this. Very similar to the code in my previous. Still have no idea if I can simply getWidth()/2 for the center point of circle

  7. #7
    alexix is offline Member
    Join Date
    Feb 2013
    Posts
    19
    Rep Power
    0

    Default Re: Center point of Circle

    Wouldn't the easiest way be using a paintComponent and a drawOval(x-radius, y-radius, radius*2, radius*2) ? x and y will be your center.

    Or you can't do that with LWJGL ?
    Last edited by alexix; 04-30-2013 at 09:23 AM.

  8. #8
    Join Date
    Apr 2013
    Posts
    41
    Rep Power
    0

    Default Re: Center point of Circle

    Quote Originally Posted by alexix View Post
    Wouldn't the easiest way be using a paintComponent and a drawOval() ?

    Or you can't do that with LWJGL ?
    its just a library so you can easily just use the drawOval.
    as for finding the middle well i doubt any of us could tell you .. i mean the whole code you posted mainly consists of variables and methods that were created in the LWJGL.
    it would be easier to use the drawOval like mentioned above.

    then with collision take the circles radius and use that to check if they collided

Similar Threads

  1. Circle within Circle in Android
    By raihan26 in forum Android
    Replies: 0
    Last Post: 08-12-2012, 09:41 PM
  2. In which circle is the Point lying?
    By nidhirastogi in forum New To Java
    Replies: 1
    Last Post: 07-03-2008, 12:12 AM

Posting Permissions

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