Did I derive a function for finding the angle of a complex number?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












When presented with a complex # written in rectangular form (x + j*y), w/ the goal of converting it to polar form, the following 2 relationships are used:



  • r = √ ( x^2 + y^2 )

  • θ = tan-1(y/x)

The equation for r works just fine but the one for θ breaks down w/ negative inputs... so either you do as I do and use whichever trig relationship makes the most sense for the given quad, or you can continue using tan but you must abide by quad dependent contingencies:



  • θ = tan-1(y/x) + 180, x < 0, y < 0

  • θ = tan-1(y/x) + 180, x < 0, y > 0

  • θ = tan-1(y/x) + 360, x > 0, y < 0

  • θ = tan-1(y/x), x > 0, y > 0

I decided to throw all of these contingencies into a single package and I would like your feedback on it:



θ = tan-1(y/x) + (1/2)((x/|x|) - 1)(180) + (1/2)((x/|x|) + 1)(-1/2)((y/|y|) - 1)(360)



Which translates to... if x < 0 ADD 180, else if x>0 AND y<0 ADD 360.



And, after simplifying, it looks like this:



θ = tan-1(y/x) - 90[(y/|y|)((x/|x|) + 1) - 2]



As far as feedback goes, I have a couple of questions:



  • Is there an equation already like this?

  • If so, is it simpler than mine?

  • If no, you might come up with a simpler approach! Please share it w/ me if so (:! I think it would be cooler if it didn't require absolute value operations but I couldn't figure out any other way to get 1 for pos #s and -1 for neg #s.

  • Did I make any mistakes? I entered complex numbers for each quad and received the correct outputs. Let me know if you spot any errors.









share|cite|improve this question





















  • You'd be better off writing a piecewise function with the canonical $arctan$ function. You don't realize it, but you're doing that with the $arctan$ (to begin with) and especially the absolute value functions.
    – Jared
    Sep 10 at 7:11










  • Please read this MathJax tutorial, which explains how to typeset mathematics on this site.
    – N. F. Taussig
    Sep 10 at 7:16






  • 1




    What if $x$ or $y$ is zero? And what do you need the formula for? Is numeric stability an issue? Note also that the standard libraries of many programming languages have a atan2(y, x) function which does the job.
    – Martin R
    Sep 10 at 7:37










  • @Jared The whole point in my quest to derive the single function was to eliminate the need for the piece wise function as I don't think they should be used when unnecessary. How would I be better off writing a piecewise function if I already wrote it (to begin with)?
    – Landon
    Sep 10 at 7:53










  • @N.F.Taussig Thank you, I will read that and use it from now on.
    – Landon
    Sep 10 at 7:54














up vote
1
down vote

favorite












When presented with a complex # written in rectangular form (x + j*y), w/ the goal of converting it to polar form, the following 2 relationships are used:



  • r = √ ( x^2 + y^2 )

  • θ = tan-1(y/x)

The equation for r works just fine but the one for θ breaks down w/ negative inputs... so either you do as I do and use whichever trig relationship makes the most sense for the given quad, or you can continue using tan but you must abide by quad dependent contingencies:



  • θ = tan-1(y/x) + 180, x < 0, y < 0

  • θ = tan-1(y/x) + 180, x < 0, y > 0

  • θ = tan-1(y/x) + 360, x > 0, y < 0

  • θ = tan-1(y/x), x > 0, y > 0

I decided to throw all of these contingencies into a single package and I would like your feedback on it:



θ = tan-1(y/x) + (1/2)((x/|x|) - 1)(180) + (1/2)((x/|x|) + 1)(-1/2)((y/|y|) - 1)(360)



Which translates to... if x < 0 ADD 180, else if x>0 AND y<0 ADD 360.



And, after simplifying, it looks like this:



θ = tan-1(y/x) - 90[(y/|y|)((x/|x|) + 1) - 2]



As far as feedback goes, I have a couple of questions:



  • Is there an equation already like this?

  • If so, is it simpler than mine?

  • If no, you might come up with a simpler approach! Please share it w/ me if so (:! I think it would be cooler if it didn't require absolute value operations but I couldn't figure out any other way to get 1 for pos #s and -1 for neg #s.

  • Did I make any mistakes? I entered complex numbers for each quad and received the correct outputs. Let me know if you spot any errors.









share|cite|improve this question





















  • You'd be better off writing a piecewise function with the canonical $arctan$ function. You don't realize it, but you're doing that with the $arctan$ (to begin with) and especially the absolute value functions.
    – Jared
    Sep 10 at 7:11










  • Please read this MathJax tutorial, which explains how to typeset mathematics on this site.
    – N. F. Taussig
    Sep 10 at 7:16






  • 1




    What if $x$ or $y$ is zero? And what do you need the formula for? Is numeric stability an issue? Note also that the standard libraries of many programming languages have a atan2(y, x) function which does the job.
    – Martin R
    Sep 10 at 7:37










  • @Jared The whole point in my quest to derive the single function was to eliminate the need for the piece wise function as I don't think they should be used when unnecessary. How would I be better off writing a piecewise function if I already wrote it (to begin with)?
    – Landon
    Sep 10 at 7:53










  • @N.F.Taussig Thank you, I will read that and use it from now on.
    – Landon
    Sep 10 at 7:54












up vote
1
down vote

favorite









up vote
1
down vote

favorite











When presented with a complex # written in rectangular form (x + j*y), w/ the goal of converting it to polar form, the following 2 relationships are used:



  • r = √ ( x^2 + y^2 )

  • θ = tan-1(y/x)

The equation for r works just fine but the one for θ breaks down w/ negative inputs... so either you do as I do and use whichever trig relationship makes the most sense for the given quad, or you can continue using tan but you must abide by quad dependent contingencies:



  • θ = tan-1(y/x) + 180, x < 0, y < 0

  • θ = tan-1(y/x) + 180, x < 0, y > 0

  • θ = tan-1(y/x) + 360, x > 0, y < 0

  • θ = tan-1(y/x), x > 0, y > 0

I decided to throw all of these contingencies into a single package and I would like your feedback on it:



θ = tan-1(y/x) + (1/2)((x/|x|) - 1)(180) + (1/2)((x/|x|) + 1)(-1/2)((y/|y|) - 1)(360)



Which translates to... if x < 0 ADD 180, else if x>0 AND y<0 ADD 360.



And, after simplifying, it looks like this:



θ = tan-1(y/x) - 90[(y/|y|)((x/|x|) + 1) - 2]



As far as feedback goes, I have a couple of questions:



  • Is there an equation already like this?

  • If so, is it simpler than mine?

  • If no, you might come up with a simpler approach! Please share it w/ me if so (:! I think it would be cooler if it didn't require absolute value operations but I couldn't figure out any other way to get 1 for pos #s and -1 for neg #s.

  • Did I make any mistakes? I entered complex numbers for each quad and received the correct outputs. Let me know if you spot any errors.









share|cite|improve this question













When presented with a complex # written in rectangular form (x + j*y), w/ the goal of converting it to polar form, the following 2 relationships are used:



  • r = √ ( x^2 + y^2 )

  • θ = tan-1(y/x)

The equation for r works just fine but the one for θ breaks down w/ negative inputs... so either you do as I do and use whichever trig relationship makes the most sense for the given quad, or you can continue using tan but you must abide by quad dependent contingencies:



  • θ = tan-1(y/x) + 180, x < 0, y < 0

  • θ = tan-1(y/x) + 180, x < 0, y > 0

  • θ = tan-1(y/x) + 360, x > 0, y < 0

  • θ = tan-1(y/x), x > 0, y > 0

I decided to throw all of these contingencies into a single package and I would like your feedback on it:



θ = tan-1(y/x) + (1/2)((x/|x|) - 1)(180) + (1/2)((x/|x|) + 1)(-1/2)((y/|y|) - 1)(360)



Which translates to... if x < 0 ADD 180, else if x>0 AND y<0 ADD 360.



And, after simplifying, it looks like this:



θ = tan-1(y/x) - 90[(y/|y|)((x/|x|) + 1) - 2]



As far as feedback goes, I have a couple of questions:



  • Is there an equation already like this?

  • If so, is it simpler than mine?

  • If no, you might come up with a simpler approach! Please share it w/ me if so (:! I think it would be cooler if it didn't require absolute value operations but I couldn't figure out any other way to get 1 for pos #s and -1 for neg #s.

  • Did I make any mistakes? I entered complex numbers for each quad and received the correct outputs. Let me know if you spot any errors.






functions complex-numbers polar-coordinates elementary-functions






share|cite|improve this question













share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked Sep 10 at 7:06









Landon

132




132











  • You'd be better off writing a piecewise function with the canonical $arctan$ function. You don't realize it, but you're doing that with the $arctan$ (to begin with) and especially the absolute value functions.
    – Jared
    Sep 10 at 7:11










  • Please read this MathJax tutorial, which explains how to typeset mathematics on this site.
    – N. F. Taussig
    Sep 10 at 7:16






  • 1




    What if $x$ or $y$ is zero? And what do you need the formula for? Is numeric stability an issue? Note also that the standard libraries of many programming languages have a atan2(y, x) function which does the job.
    – Martin R
    Sep 10 at 7:37










  • @Jared The whole point in my quest to derive the single function was to eliminate the need for the piece wise function as I don't think they should be used when unnecessary. How would I be better off writing a piecewise function if I already wrote it (to begin with)?
    – Landon
    Sep 10 at 7:53










  • @N.F.Taussig Thank you, I will read that and use it from now on.
    – Landon
    Sep 10 at 7:54
















  • You'd be better off writing a piecewise function with the canonical $arctan$ function. You don't realize it, but you're doing that with the $arctan$ (to begin with) and especially the absolute value functions.
    – Jared
    Sep 10 at 7:11










  • Please read this MathJax tutorial, which explains how to typeset mathematics on this site.
    – N. F. Taussig
    Sep 10 at 7:16






  • 1




    What if $x$ or $y$ is zero? And what do you need the formula for? Is numeric stability an issue? Note also that the standard libraries of many programming languages have a atan2(y, x) function which does the job.
    – Martin R
    Sep 10 at 7:37










  • @Jared The whole point in my quest to derive the single function was to eliminate the need for the piece wise function as I don't think they should be used when unnecessary. How would I be better off writing a piecewise function if I already wrote it (to begin with)?
    – Landon
    Sep 10 at 7:53










  • @N.F.Taussig Thank you, I will read that and use it from now on.
    – Landon
    Sep 10 at 7:54















You'd be better off writing a piecewise function with the canonical $arctan$ function. You don't realize it, but you're doing that with the $arctan$ (to begin with) and especially the absolute value functions.
– Jared
Sep 10 at 7:11




You'd be better off writing a piecewise function with the canonical $arctan$ function. You don't realize it, but you're doing that with the $arctan$ (to begin with) and especially the absolute value functions.
– Jared
Sep 10 at 7:11












Please read this MathJax tutorial, which explains how to typeset mathematics on this site.
– N. F. Taussig
Sep 10 at 7:16




Please read this MathJax tutorial, which explains how to typeset mathematics on this site.
– N. F. Taussig
Sep 10 at 7:16




1




1




What if $x$ or $y$ is zero? And what do you need the formula for? Is numeric stability an issue? Note also that the standard libraries of many programming languages have a atan2(y, x) function which does the job.
– Martin R
Sep 10 at 7:37




What if $x$ or $y$ is zero? And what do you need the formula for? Is numeric stability an issue? Note also that the standard libraries of many programming languages have a atan2(y, x) function which does the job.
– Martin R
Sep 10 at 7:37












@Jared The whole point in my quest to derive the single function was to eliminate the need for the piece wise function as I don't think they should be used when unnecessary. How would I be better off writing a piecewise function if I already wrote it (to begin with)?
– Landon
Sep 10 at 7:53




@Jared The whole point in my quest to derive the single function was to eliminate the need for the piece wise function as I don't think they should be used when unnecessary. How would I be better off writing a piecewise function if I already wrote it (to begin with)?
– Landon
Sep 10 at 7:53












@N.F.Taussig Thank you, I will read that and use it from now on.
– Landon
Sep 10 at 7:54




@N.F.Taussig Thank you, I will read that and use it from now on.
– Landon
Sep 10 at 7:54















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "69"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2911611%2fdid-i-derive-a-function-for-finding-the-angle-of-a-complex-number%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2911611%2fdid-i-derive-a-function-for-finding-the-angle-of-a-complex-number%23new-answer', 'question_page');

);

Post as a guest













































































這個網誌中的熱門文章

tkz-euclide: tkzDrawCircle[R] not working

How to combine Bézier curves to a surface?

1st Magritte Awards