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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:14:21+00:00 2026-05-12T09:14:21+00:00

I am creating a bouncing object that can bounce around a 2D rectangular room.

  • 0

I am creating a bouncing object that can bounce around a 2D rectangular room. I have read through the answer of the other question about using velocityX and velocityY instead of normal direction angle. OK, it sounds easier so I implement the following mathematical methods below. However, there is one difference. I required that I input an angle and which (horizontal/vertical) wall the object is hit.

+(double) getDirection:(double) x1:(double) y1: (double) x2: (double) y2{
    return (atan2(y2-y1,x2-x1) * 180) / 3.14;
}
+(double) getLengthDir_X:(double) dis: (double) dir{
    return (dis*cos(dir));
}
+(double) getLengthDir_Y:(double) dis: (double) dir{
    return (dis*sin(dir));
}

+ (float) getBouncedAngle: (float) dir: (int) HVVar{

    if (dir < 0)dir+=360;
    else if (dir >= 360)dir-=360;

    NSLog(@"in dir %f", dir);

    float initialVX = [self getLengthDir_X:100 :dir],
    initialVY = [self getLengthDir_Y:100 :dir];

    NSLog(@"x,y %f %f", initialVX, initialVY);

    if (HVVar == 0){//horizontal wall
        initialVX = -initialVX;
    }else if (HVVar == 1){//vertical wall
        initialVY = -initialVY;
    }

    NSLog(@"x,y %f %f", initialVX, initialVY);

    float newDir = [self getDirection:0 :0 :initialVX :initialVY];

    NSLog(@"dir : %f ---> dir : %f", dir, newDir);

    return newDir;
}

But I get very strange results. I get wrong angles sometimes. Am I missing something?

2009-08-13 23:31:19.854 X[2936:20b] in dir -0.049634
2009-08-13 23:31:19.854 X[2936:20b] x,y 99.876846 -4.961388
2009-08-13 23:31:19.855 X[2936:20b] x,y -99.876846 -4.961388
2009-08-13 23:31:19.857 X[2936:20b] dir : -0.049634 ---> dir : -177.246017
2009-08-13 23:31:21.220 X[2936:20b] in dir -177.246017
2009-08-13 23:31:21.220 X[2936:20b] x,y 25.124613 -96.792320
2009-08-13 23:31:21.221 X[2936:20b] x,y -25.124613 -96.792320
2009-08-13 23:31:21.222 X[2936:20b] dir : -177.246017 ---> dir : -104.604294
2009-08-13 23:31:21.253 X[2936:20b] in dir -104.604294
2009-08-13 23:31:21.253 X[2936:20b] x,y -59.644127 80.265671
2009-08-13 23:31:21.255 X[2936:20b] x,y 59.644127 80.265671
2009-08-13 23:31:21.256 X[2936:20b] dir : -104.604294 ---> dir : 53.411633
  • 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-12T09:14:21+00:00Added an answer on May 12, 2026 at 9:14 am

    Your sin and cos functions expect arguments in radians. You’re giving them arguments in degrees.

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

Sidebar

Ask A Question

Stats

  • Questions 226k
  • Answers 226k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is that the exact code from your app? For starters,… May 13, 2026 at 1:13 am
  • Editorial Team
    Editorial Team added an answer Yes, they're equivalent. You need braces when the expression is… May 13, 2026 at 1:13 am
  • Editorial Team
    Editorial Team added an answer You need to be quite careful with the plumbing: Call… May 13, 2026 at 1:13 am

Related Questions

I am creating a small modal form that is used in Winforms application. It
I am creating a program that will be installed using the .net installer project.
I am creating a GUI for a machine that runs remote (WinXP) or on
I am creating a Windows Service in C# that processes messages from a queue.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.