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

  • Home
  • SEARCH
  • 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 7955197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:39:29+00:00 2026-06-04T03:39:29+00:00

I have a simple game animation made in java. It is of three planets

  • 0

I have a simple game animation made in java. It is of three planets rotating around an axis. Each planet is an instance of the class Planet and they have an update method which, every time it is run, the orbit’s rotation angle increases and the position is updated acording to the angle and a few predetermined variables like distance from the “sun”. From here, you can determine the position of the planet with simple trigonometry. In this case:

Sin(angle) = op/hyp = y/distance
therefore
Sin(angle)*hyp = op

Cos(angle) = ady/hyp = x/distance
therefore
Cos(angle)*hyp = ady

where the hypothenuse is the distance to the sun and the adyacent and oposite sides are the x and y values respectively. I figured this would work, until I tried it out. It gave me an eliptical rotation. Here is the code that updates the planet’s rotation (orbit center is the sun’s center position):

position.x = ((Math.cos(orbitAngle) * orbitDistance) + orbitCenter.x);
position.y = ((Math.sin(orbitAngle) * orbitDistance) + orbitCenter.y);

What could be wrong?

EDIT:

I realized this problem by placing an object with its center in the position specified by orbit center

Here is the full code of the planet class:

public class Planet
{
    protected Image image;

    protected Vector2 position;
    protected final Vector2 orbitCenter;
    protected float rotation;
    protected Vector2 imageSize;

    protected final float rotationSpeed;
    protected final float orbitDistance;

    protected float orbitAngle;
    protected final float orbitAngleSpeed;

    public Planet(Image image, float orbitDistance, float rotationSpeed, Vector2 orbitCenter, float orbitAngleSpeed)
    {
        this.image = image;
        this.position = new Vector2(orbitCenter.x, orbitCenter.y - orbitDistance);
        this.orbitCenter = orbitCenter;
        this.rotation = 0;
        this.imageSize = new Vector2(image.getWidth(null), image.getHeight(null));
        this.rotationSpeed = rotationSpeed;
        this.orbitDistance = orbitDistance;
        this.isMouseOver = false;
        this.isPressed = false;
        this.orbitAngle = 0;
        this.orbitAngleSpeed = orbitAngleSpeed;
    }

    public void Update()
    {
        orbitAngle += orbitAngleSpeed;
        if(orbitAngle > Math.PI * 2)
            orbitAngle %= Math.PI * 2;

        position.x = ((Math.cos(orbitAngle) * orbitDistance) + orbitCenter.x);
        position.y = ((Math.sin(orbitAngle) * orbitDistance) + orbitCenter.y);
    }

    public void Draw(Graphics2D g)
    {
        g.rotate(rotation, position.x + imageSize.x / 2, position.y + imageSize.y / 2);
        g.drawImage(image, (int)position.x, (int)position.y, null);
        g.rotate(-rotation, position.x + imageSize.x / 2, position.y + imageSize.y / 2);
    }
}

Here is the class that tests the planet class. You can download the jar it needs to work from here: foxtailgames.net/AppletSource.jar. Here is the tester class (you will probably have to import a few things though if you do it in eclipse or netbeans it will give you the imports):

public class PlanetTest extends AppletCore
{
    public void resizeScreen() {resize(800, 800);}

    Image center;
    Planet p;

    public void LoadContent()
    {
        p = new Planet(loadImage("images/GameMenuCircles/Planet1.png"), 100f, 0.02f, new Vector2(400, 400), 0.005f);
        center = loadImage("images/GameMenuCircles/Center.png");
    }

    public void Update(GameTime gameTime)
    {
        p.Update();
    }

    public void Draw(Graphics2D g, GameTime gameTime)
    {
        g.drawImage(center, 400 - center.getWidth(null)/2, 400 - center.getWidth(null)/2, null);
        p.Draw(g);
        g.setColor(Color.green);
        g.drawLine(400, 400, 500, 400);
        g.drawLine(400, 400, 400, 500);
        g.drawLine(400, 400, 300, 400);
        g.drawLine(400, 400, 400, 300);
        g.setColor(Color.white);
    }
} 
  • 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-04T03:39:30+00:00Added an answer on June 4, 2026 at 3:39 am

    Your rotation is set to 0 in the above so i assume you are not rotating the picture at the moment. What i think is happening is the orbit circle you are producing is fine, but the location you are drawing the planet is off.

    Below is an image of how Swing would draw the circle, so the overlap you experience is because of this.

    You need to adjust the position you draw the circle by how half the width so it sits over the center of the orbit.

    Image of how Swing draws.

    EDIT: You’ve alter some code but what you need to change is the draw method of he planet:

    public void Draw(Graphics2D g) {
            g.rotate(rotation, position.x + imageSize.x / 2, position.y + imageSize.y / 2);
            g.drawImage(image, (int)position.x, (int)position.y, null); //here
            g.rotate(-rotation, position.x + imageSize.x / 2, position.y + imageSize.y / 2);
        }
    

    This line needs to be:

    g.drawImage(image, (int)position.x - imageSize.width, (int)position.y - imageSizee.height, null); //here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have three simple images each for 2 hens (6 images) which I am
I'm confused about changing an instance's animation. I'm working on a really simple game
I have just began learning Java programming, I have created a simple game using
I have a simple game activity. I start it and than press the back
I have a simple JavaScript game that sends a score to PHP by adding
Say I have simple program that emulates a board game with a number of
I'm writing a simple game and I'm going to have the mouse control the
I have a simple tank wars style game using the allegro open source library.
Trying to make simple minesweeper game in python, but have one problem. I have
I'm working on a simple board game in qt, and i have some problem

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.