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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:10:07+00:00 2026-06-16T05:10:07+00:00

So I am working on a 3-D scene where I need to convert to

  • 0

So I am working on a 3-D scene where I need to convert to and from polar coordinates at will, and have written a function to help me convert. The problem is that it is resulting in a NaN for one of the angles pretty regularly. The function I am using is as follows:

toPolar: function(x,y,z){
    var sqrd = (x*x)+(y*y)+(z*z)
    var radius = Math.pow(sqrd,.5)
    var theta = Math.acos(z/radius)
    var phi = Math.asin(y/x)
    var toReturn={
        r:radius,
        t:theta,
        p:phi
    }
    return toReturn
}

Phi is what is returning NaN, and Although I though I figured out where it resulted in NaN it seems as though it is happening in certain points all throughout the scene

You can see the problem here:
http://cabbibo.com/sketches/audioSketch3/

Where in the upper left hand corner you see the polar and cartesian coordinates of the camera, and the last section of the polar coordinates (phi) will show up as NaN from time to time.

I assume its some sort of problem with my math, because I am not that good at it, but it seems like it might be a different issue, such as me not understanding how to use Math.asin …

Thanks for your time, and let me know if there is any other information anybody needs!

Isaac

  • 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-16T05:10:08+00:00Added an answer on June 16, 2026 at 5:10 am

    If you’re expecting phi to be like Azimuth (e.g. in the horizontal plane over, -pi -> pi) you should use atan2.

    var phi = Math.atan2(y,x);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To set the scene, I'm currently working on an XML adapter for Android that
Working with an undisclosed API, I found a function that can set the number
Working on game where plates will be falling from top to bottom. Some plates
Working in Java FX 2.2. The Scene has a horizontal width that is fixed
I am working on a flash game that requires me to instantiate objects from
I basically have 3 layers ( Window > Scene > View ) that each
I am working on website performance and need a little bit of help determining
I am in trouble and need your help. I am currently working on a
I have a custom class derived from QGraphicsView that implements a slot call scrollHorizontal(int
I have a scene that is rendered to texture via FBO and I am

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.