简体   繁体   English

如何获得对角圆的坐标?

[英]How do I get the coordinates of a diagonal circle?

I am almost done of getting the coordinates of a diagonal circle. 我几乎完成了获得对角圆的坐标。

Here is what I have so far. 这是我到目前为止所拥有的。

// Center point
double centerX;
double centerY;
double centerZ;
for (double degree = 0D; degree < 360D; degree = degree + 8D) {
    double angle = degree * Math.PI / 180D;
    // Difference from the center
    double x = 1.5D * Math.cos(angle);
    double y;
    if (degree >= 0D && degree < 90D) {
        y = degree / 90D;
    } else if (degree >= 90D && degree < 180D) {
        y = 1D - ((degree - 90D) / 90D);
    } else if (degree >= 180D && degree < 270D) {
        y = -1D * ((degree - 180D) / 90D);
    } else {
        y = -1D * (1D - ((degree - 270D) / 90D));
    }
    double z = 1.5D * Math.sin(angle);
    // New point
    double pointX = centerX + x;
    double pointY = centerY + y;
    double pointZ = centerZ + z;
}

Here is the output in a game. 这是游戏中的输出。 It is not perfect because it creates some edges and it looks inefficient to me. 它并不完美,因为它会产生一些边缘,对我来说看起来效率低下。

How do I correct it? 我该如何纠正? Is there a better way to do this? 有一个更好的方法吗?

This should look similar to what you have already, but it's simpler and smoother: 这应该与您已经看到的类似,但它更简单,更顺畅:

double y = 1.0D * Math.sin(angle);

Now, with these dimensions, the result is not quite a circle, but a stretched ellipse. 现在,使用这些尺寸,结果不是一个圆圈,而是一个拉伸的椭圆。 If you want a circle, make sure the coefficients on the cosine and sine obey the Pythagorean Theorem . 如果你想要一个圆,请确保余弦和正弦上的系数遵循毕达哥拉斯定理 For example: 例如:

double x = 1.5D * Math.cos(angle);
double y = 0.9D * Math.sin(angle);
double z = 1.2D * Math.sin(angle);

These coefficients will ensure that x^2 + y^2 + z^2 is a constant for every angle. 这些系数将确保x ^ 2 + y ^ 2 + z ^ 2对于每个角度都是常数。 You can verify that this is true, given the identity cos^2 + sin^2 = 1. (The coefficient representing the hypotenuse should be attached to the coordinate that uses a different trig function than the other two.) 鉴于标识cos ^ 2 + sin ^ 2 = 1,您可以验证这是否为真。(表示斜边的系数应附加到使用与其他两个不同的触发函数的坐标。)

For the most maintainable code, you might find it better to assign (x, y, z) = (cos, sin, 0) and then apply a rotation matrix, or a sequence of rotation matrices, to the vector (x, y, z). 对于最易维护的代码,您可能会发现分配(x,y,z)=(cos,sin,0)然后将一个旋转矩阵或一系列旋转矩阵应用于向量(x,y, Z)。 This will be easier to read and harder to mess up, if you want to fine-tune the amount of rotation later. 如果您想稍后微调旋转量,这将更容易阅读,更难搞乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM