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 9078585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:39:40+00:00 2026-06-16T19:39:40+00:00

So far I am able to make an object called satelite rotate around another

  • 0

So far I am able to make an object called satelite rotate around another object called turret in an elliptical manner. The only thing is that before the satelite starts rotating around the turret it has an initial position (Figure 1). However after the first frame the satelite is moved from it’s initial position to somewhere else(Figure 2). I’m trying to have the satelite enter the elliptical rotation from it’s initial position, not for it to be moved to another position and then start the elliptical rotation from that new position.

Figure 1 . . . . . . . . . . . . . . . . . . . Figure 2

Initial position at first frame

After first frame resulting position http://s1.postimage.org/xscznk8bz/After_Initial_Position.png

Code :

private var fixedPoint1:int = 0;
private var fixedPoint2:int = 0;
private var currentDegrees:Number = 0;

private function onEnterFrame(event:Event):void
{   
    var dx:Number = turret.x - satelite.x; // This code deals with turret rotation
    var dy:Number = turret.y - satelite.y; // So does this code

    var angle:Number = Math.atan2(dy, dx); // As does this code

    turret.rotation = (angle * 180 / Math.PI); // Finally done with turret rotation code

    if (firstRun) {
        currentDegrees = angle * 180 / Math.PI;
        fixedPoint1 = satelite.x;
        fixedPoint2 = satelite.y;
        firstRun = false;
    }

    currentDegrees += 1;

    var radians:Number = currentDegrees * Math.PI / 180;
    var posX:Number = turret.x + Math.cos(radians) * (fixedPoint1);
    var posY:Number = turret.y + Math.sin(radians) * (fixedPoint2);

    satelite.x = posX;
    satelite.y = posY;      
}

I kind of understand why it’s moving the satelite from it’s initial position to it’s elliptical position based off the equations used. I just can’t figure out how to edit the equations or variables to have the ellipse “start from” (maybe encompass is a better word) the initial position.

Thank you for any help provided.

Update :

This code works, but it resembles a circular orbit instead of an elliptical orbit.
Thank you Markus Jarderot!

private function onEnterFrame(event:Event):void
{   
        var dx:Number = turret.x - satellite.x;
        var dy:Number = turret.y - satellite.y;

        var angle:Number = Math.atan2(dy, dx);

        turret.rotation = (angle * 180 / Math.PI);

        if (firstRun) {
             currentAngle = (180 * Math.PI/180); // Start out at pi
                                                 // instead of 0 for some reason?

            fixedPointX = turret.x - satellite.x; // xRadius = distance between turret.x and satellite.x
            fixedPointY = turret.y - satellite.y; // yRadius = distance between turret.y and satellite.y

            firstRun = false;
        }

        currentAngle += Math.PI / 180.0; // one degree
        if (currentAngle > Math.PI) currentAngle -= 2.0 * Math.PI;

        var cosAngle : Number = Math.cos(currentAngle);
        var sinAngle : Number = Math.sin(currentAngle);

        satellite.x = turret.x + cosAngle * fixedPointX + sinAngle * fixedPointY;
        satellite.y = turret.y - sinAngle * fixedPointX + cosAngle * fixedPointY;
}
  • 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-16T19:39:42+00:00Added an answer on June 16, 2026 at 7:39 pm

    That looks like an incomplete version of a circular path.

    var dx : Number = satellite.x - turret.x;
    var dy : Number = satellite.y - turret.y;
    
    var angle : Number = Math.atan2(dy, dx);
    
    turrent.rotation = angle;
    
    if (firstRun) {
        currentAngle = 0; // radians relative to fixed point
    
        fixedPointX = dx;
        fixedPointY = dy;
    
        firstRun = false;
    }
    
    currentAngle += Math.PI / 180.0; // one degree, or 1/360th cycle.
    if (currentAngle > Math.PI) currentAngle -= 2.0 * Math.PI;
    
    var cosAngle : Number = Math.cos(currentAngle);
    var sinAngle : Number = Math.sin(currentAngle);
    
    satellite.x = turret.x + cosAngle * fixedPointX + sinAngle * fixedPointY;
    satellite.y = turret.y - sinAngle * fixedPointX + cosAngle * fixedPointY;
    

    This is using a standard rotation matrix based on the moving angle. It will rotate in a circle around the turret, starting at the initial position.

    If you want an elliptical orbit, you need to have one more reference point: Either another point along the orbit, or the initial velocity vector.

    Demo: http://jsfiddle.net/MizardX/dRFay/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make an object rotate around its axis? i.e. having the moon
So far the only way I have been able to keep index.yaml updated when
So far I was able to find users in LDAP but I don't know
I am working on making a simple drawing program. So far I am able
I haven't been able to find any documentation on Android's sync services, so far
I'm learning OpenGL and SDL and so far I've been able to properly draw
streak.com is able to create a very rich experience integrated with gmail. As far
I have this so far: http://jsfiddle.net/u5vhS/54/ . What I want to be able to
I'm trying to get a better understanding than I've been able to so far...it's
I am a beginner with MSBuild. So far I have been able to create

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.