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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:24:11+00:00 2026-05-12T17:24:11+00:00

This piece of code has been taken from a game built with XNA framework.

  • 0

This piece of code has been taken from a game built with XNA framework. I’d like some explanation of how it works in terms of trig and physics.

ball.velocity = new
Vector2((float)Math.Cos(cannon.rotation),
(float)Math.Sin(cannon.rotation));

ball.rotation is the rotation of a sprite in what i should think, radians.

Why is it that they can use the angle in radians only to find the x position then the same thing to find the y position of a direction of where the hypotenuse is pointing.

Reason why I asked this. I would like to get a feel of how this frameworks does calculations for trig. I am trying to get a sprite to turn in the direction of where the mouse is, that is: x and y is known, i just need the angle.

So there are 2 questions here. explaining that code above and pointing a sprite in the direction of a known point.

Update:

I found out that the point a which the object is at is not (0,0) because xna uses inverse coordinate system. So now the variables I have are these:

point of object.
point of mouse.

  • 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-12T17:24:11+00:00Added an answer on May 12, 2026 at 5:24 pm

    Every angle corresponds to a point on the unit circle (the unit circle is the unique circle centered at the origin with radius one; that is, the unit circle is the set of points satisfying x^2 + y^2 = 1). The correspondence is the following: given an angle theta, theta corresponds to the point (cos theta, sin theta). Why does (cos theta, sin theta) live on the unit circle? Because of everyone’s favorite identity

    cos^2 theta + sin^2 theta = 1.
    

    That is with x = cos theta and y = sin theta, the point (x, y) satisfies x^2 + y^2 = 1 so that (x, y) is on the unit circle.

    To reverse this, given a point on the unit circle you can find the angle by using the inverse tangent (perhaps known to you as arctan or atan and sometimes tan-1). Precisely, given (x, y) on the unit circle you can find the angle corresponding to (x, y) by computing theta = arctan(y / x).

    Of course, there are some messy details here. The function arctan can’t tell the difference between the inputs (x, y) and (-x, -y) because y / x and (-y / -x) have the same sign. Further, arctan can’t handle inputs where x = 0. So we typically handle these by defining the function atan2 that will handle these messy details for us

    atan2(y, x) = arctan(y / x)       if x > 0
                = pi + arctan(y / x)  if y >= 0, x < 0
                = -pi + arctan(y / x) if y < 0, x < 0
                = pi / 2              if y > 0, x = 0
                = -pi / 2             if y < 0, x = 0
                = NaN                 if y = 0, x = 0
    

    In C#, Math.Atan is the function arctan that I have referred to above, and Math.Atan2 is the function atan2 that I have referred to above.

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

Sidebar

Related Questions

No related questions found

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.