The conversion from Cartesian to Polar coordinates returned a result of NaN

Currently, I am working on a 3-D scene that requires me to convert between polar and Cartesian coordinates as needed. To assist with this task, I have developed a function for conversion. However, I am encountering a recurring issue where one of the angles frequently results in NaN. The function I am utilizing is outlined below:

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
}

The problematic angle is Phi, which often returns NaN. Despite my efforts to pinpoint the source of this issue, it appears to occur unpredictably throughout the scene.

You can observe the problem here:

In the top left corner of the display, you will find the camera's polar and Cartesian coordinates. Occasionally, the final section of the polar coordinates (Phi) displays as NaN.

I suspect there may be an error in my mathematical calculations, as my proficiency in math is limited. It is possible that the problem lies in how I am using Math.asin...

Thank you for your attention, and please let me know if further information is required!

-Isaac

Answer №1

When anticipating phi to function similar to Azimuth (for example, in the horizontal plane spanning from -pi to pi), atan2 should be utilized.

let phi = Math.atan2(y,x);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The length of the HTTP response in Angular is not defined

Currently, I am utilizing Angular in conjunction with jQuery Mobile to develop multiple pages, but I have encountered an obstacle when using the $http service to connect to my JSON requests. While populating a few arrays with functions and successfully ret ...

Even after I delete and refresh, the persistent cookie sticks around

I attempted to delete the user's authentication cookie using $cookieStore.remove('.ASPXAUTH'). Despite this, when I refresh the page, the cookie persists and the user can still access the page instead of getting redirected to the login page. ...

Eliminating Non-Breaking Spaces with the Click of a Button

Having some difficulty with the following Javascript code. I'm not very skilled in writing Javascript, so any assistance on adjusting it to replace any   with a regular space would be greatly appreciated. Thank you function copyToClipboard( ...

Issues with FlexItems not fully occupying available space when using flex wrap

Before presenting my question, here is the relevant code snippet: const App: FC = () => { const [boardWidth, _setBoardWidth] = useState<number>(1400); const [boardHeight, _setBoardHeight] = useState<number>(1000); const [cellWidth, _se ...

Saving an image to a variable in React Native by using a URL

Is it possible to save an image from a URL into a variable and then use it in the Image component? In the code snippet provided below, the image is loaded directly, but I would like to create a function that stores the image in a variable for offline use ...

Unable to cancel the RTK query request

It's quite a dilemma. I need to handle the request differently when there is no user present. I've attempted different approaches like this and that const { data: carts = [] as ICart[], isFetching } = api.useGetCartProductsQuery(user.id, { skip: ...

Activating the delete event trigger for a tinyMCE object

How can I create a function that activates when a user deletes an object in tinyMCE? I want to remove uploaded images from a cache folder whenever a user deletes an image from the tinyMCE editor. If they upload an image and then delete it, I would like an ...

Go through a list of objects in one single iteration

$(document).ready(function() { allQuestions is an array of objects that plays the role of providing questions (question), answers (choices), and correct responses(correctAnswer) for my application. var allQuestions = [{question: "If you could hav ...

Is there a way to verify file types using Vuelidate?

Is there a way to validate file types like png, jpg, and jpeg using Vue.js's Vuelidate library? ...

Tips for altering the background of a video on Vonage

Hello everyone, Currently, I am incorporating the Vonage API for video calling into my project. I would like to tweak the video background - does anyone have any ideas on how to accomplish this? I eagerly await your responses! Thank you in advance! ...

Ways to show various div elements when a checkbox is clicked

My goal is to have the div element show when I click on the checkbox and hide when I uncheck it. The code below works fine in terms of functionality. However, the issue arises when I click on both checkbox1 and checkbox2, causing the div element to overri ...

Error due to callback function in FullCalendar selection in Javascript

Currently, I am in the process of integrating fullcalendar into a project that I have been working on. Unfortunately, I have encountered some errors with the select: callback function when attempting to submit an ajax request. Here is what my select: callb ...

Issues with the Tumblr platform's back-to-top button functionality

I am quite comfortable with HTML and CSS, but I'm struggling to make the 'back to top' button work on my Tumblr page. Can someone please give me a hand? I've included some JQuery code to make the text fade in and out when scrolling (inf ...

Issue with triggering onclick event in both parent and child components

I am working with 2 components in Vue.js: An Accordion header that opens its content when clicked on. A Cog icon that opens a mini-modal menu. The issue arises when I click on the cog icon - I do not want the Accordion to open its content. Before click ...

A common error in NodeJS occurs when the "identifier immediately follows a numeric literal" in a variable JSON object while using jade pages

My NodeJS App sends a json object from MongoDB to the jade page. I can successfully use the json object by referencing ${data}, except when I try to use it in a javascript section on the jade page. This results in an error: SyntaxError: identifier starts ...

What is the method for transferring the data of a node within an XML file to a different page using PHP?

Is it possible to transfer the content of a node in XML to another page using PHP? page.php <!DOCTYPE html> <html> <head> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1 targe ...

Changing CSS class on button click in React.js app

Is there a way to add a blur effect to my background when a user clicks a specific button? I want to update my CSS class accordingly. Below is the current CSS class: .post_options { width: 100%; height: 100%; float: left; background-color ...

Is Consistency Possible with CSS Transition Direction?

Take a look at this example: https://codepen.io/jon424/pen/XWzGNLe In the provided code snippet, there is a button that can toggle the visibility of an image. When clicked, the image disappears from bottom to top and reappears when clicked again. The use ...

Issue with Material UI scrollable tabs failing to render properly in Internet Explorer

Currently, we are integrating Material UI into our tab control for our React Web UI. Everything is functioning smoothly in Chrome, but when we attempted to test it in IE, the page failed to load and presented the error below: Unhandled promise rejection ...

Designing a navigation feature for language selection that includes redirecting and storing preferences locally

Currently, I have a web application built on Umbraco (MVC .NET) with only two roots: "English" and "Swedish". The default webpage is in English, while Swedish is optional for the user. To allow users to switch between languages, I have implemented a dropdo ...