从笛卡尔坐标到极坐标

Plot from Cartesian to polar

我正在使用左声道和右声道创建李萨如矢量示波器。左边是 x,右边是 y,两者都不会超过 1 和 -1 值。这些坐标也以 45 度角移动,以提供以下视图。

所以我正在做一个非常简单的

// 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)) 

这给了我那张照片的结果。

如何绘制极坐标图形,使其看起来不像正方形,而像圆形? 我试图获得这种观点,但对它与左翼和右翼的关联方式感到非常困惑。我使用 https://en.wikipedia.org/wiki/Polar_coordinate_system 作为参考。

我明白我想要什么了。

我试图在极坐标图中绘制这些坐标。我做错了。

我最终意识到,为了转换 x,y 坐标,我需要自己定义半径和角度在我的 x,y 图表中应该代表什么。在我的例子中,我希望半径是 x 和 y

的最大绝对值

唯一的问题是试图找出如何使用 x 和 y 值计算角度。

这就是我希望我的圈子运作的方式,

  1. x = y时,角度为0
  2. x = 1 & y = 0时,角度为45.
  3. x = 1 & y = -1时,角度为90.
  4. x = 0 & y = 1时,则角度为-45.
  5. x = -1 & y = 1时,角度为-90.

根据此信息,您可以算出圆的其余坐标,最多 180 & - 180 度角。

我必须使用条件(if else 语句)来正确找出给定 x 和 y 的正确角度。

然后绘制极坐标,只需使用 cos 和 sin 转换为 x、y 坐标即可。

我喜欢编程,只是微积分不太好。