Search code examples
c++polar-coordinates

Plot from Cartesian to polar


I'm using the Left and Right audio channels to create a Lissajous Vectorscope. Left is x and Right is y, both which never goes beyond 1 and -1 values. These coordinates are also shifted at a 45 degree angle to give me the following view.

enter image description here

So I'm doing a very simple

// converting x and y value from (-1 - 1) to (0 - 1)
float x = LeftChannelValue/2 + 0.5
float y = RightChannelValue/2 + 0.5

// multiplying the width and height with X and Y to get a proper square
// width and height have to be the same value 
float new_X = x*(width*0.5)
float new_Y = y*(height*0.5)

// doing two dimensional rotating to 45 degrees so it's easier to read
float cosVal = cos(0.25*pi)
float sinVal = sin(0.25*pi)

float finalX = (((new_X*cosVal)-(new_Y *sinVal))) + (width*0.5) //adding to translate back to origin 
float finalY = ((new_X*sinVal) + (new_Y *cosVal)) 

This gives me the results on that picture.

How would I graph the polar coordinates so that it doesn't look like a square, it looks like a circle? enter image description here I'm trying to get this view but am absolutely confused about how that would correlate with the left and right. I'm using https://en.wikipedia.org/wiki/Polar_coordinate_system as a reference.


Solution

  • I figured out what I wanted.

    I was trying to plot those coordinates in a polar graph. I was going about it all wrong.

    I eventually realized that in order for me to convert the x,y coordinates, I needed my own definition for what a radius and an angle should represents in my x,y chart. In my case, I wanted the radius to be the largest absolute value of x and y

    The only problem was trying to figure out how to calculate an angle using x and y values.

    This is how I wanted my circle to work,

    1. when x = y, the angle is 0.
    2. when x = 1 & y = 0, then angle is 45.
    3. when x = 1 & y = -1, then angle is 90.
    4. when x = 0 & y = 1, then angle is -45.
    5. when x = -1 & y = 1, then angle is -90.

    given this information, you can figure out the rest of the coordinates for the circle up to 180 & - 180 degree angle.

    I had to use conditions (if else statements) to properly figure out the correct angle given x and y.

    And then to graph the polar coordinate, you just convert using the cos and sin conversion to x, y coordinates.

    I like to program, I'm just not good with calculus.