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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:22:10+00:00 2026-05-24T16:22:10+00:00

i’ve been studying this code example for Rung-Kutta physics but i don’t understand what

  • 0

i’ve been studying this code example for Rung-Kutta physics but i don’t understand what is happening with the acceleration(p:Point, v:Point):Point function. the function accepts 2 point objects as required arguments but doesn’t use them in the function while simply returning a new point.

i’m unfamiliar with this style of argument passing. can someone explain the significance of this function to me?

the source is from Keith Peters’ book Advanced ActionScript 3.0 Animation, Chapter 6 – Advanced Physics, page 246.

package {
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.utils.getTimer;

    public class RK2 extends Sprite
    {
        private var _ball:Sprite;
        private var _position:Point;
        private var _velocity:Point;
        private var _gravity:Number = 32;
        private var _bounce:Number = -0.6;
        private var _oldTime:int;
        private var _pixelsPerFoot:Number = 10;


        public function RK2()
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            _ball = new Sprite();
            _ball.graphics.beginFill(0xff0000);
            _ball.graphics.drawCircle(0, 0, 20);
            _ball.graphics.endFill();
            _ball.x = 50;
            _ball.y = 50;
            addChild(_ball);

            _velocity = new Point(10, 0);
            _position = new Point(_ball.x / _pixelsPerFoot, _ball.y / _pixelsPerFoot);

            _oldTime = getTimer();
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }

        private function onEnterFrame(event:Event):void
        {
            var time:int = getTimer();
            var elapsed:Number = (time - _oldTime) / 1000;
            _oldTime = time;

            var accel1:Point = acceleration(_position, _velocity);

            var position2:Point = new Point();
            position2.x = _position.x + _velocity.x * elapsed;
            position2.y = _position.y + _velocity.y * elapsed;

            var velocity2:Point = new Point();
            velocity2.x = _velocity.x + accel1.x * elapsed;
            velocity2.y = _velocity.y + accel1.x * elapsed;

            var accel2:Point = acceleration(position2, velocity2);

            _position.x += (_velocity.x + velocity2.x) / 2 * elapsed;
            _position.y += (_velocity.y + velocity2.y) / 2 * elapsed;

            _velocity.x += (accel1.x + accel2.x) / 2 * elapsed;
            _velocity.y += (accel1.y + accel2.y) / 2 * elapsed;

            if(_position.y > (stage.stageHeight - 20) / _pixelsPerFoot)
            {
                _position.y = (stage.stageHeight - 20) / _pixelsPerFoot;
                _velocity.y *= _bounce;
            }
            if(_position.x > (stage.stageWidth - 20) / _pixelsPerFoot)
            {
                _position.x = (stage.stageWidth - 20) / _pixelsPerFoot;
                _velocity.x *= _bounce
            }
            else if(_position.x < 20 / _pixelsPerFoot)
            {
                _position.x = 20 / _pixelsPerFoot;
                _velocity.x *= _bounce;
            }

            _ball.x = _position.x * _pixelsPerFoot;
            _ball.y = _position.y * _pixelsPerFoot;
        }

        private function acceleration(p:Point, v:Point):Point
        {
            return new Point(0, _gravity);
        }
    }
}
  • 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-05-24T16:22:12+00:00Added an answer on May 24, 2026 at 4:22 pm

    I think the author may be using the method acceleration as a place holder, perhaps for updates on a subsequent chapter.

    Of course as it is right now, the acceleration method could be rewritten as

    private function acceleration(...rest):Point {
        return new Point(0, _gravity);
    }
    

    Or the arguments could be removed completely (though that would require the places where the method is called to be updated to not contain any arguments.)

    This isn’t a style of programming per se, but, I have seen this type of placeholder code put into books before.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.