3

与えられた:

x = originX + radius * Cos(角度);

y = originY + 半径 * Sin(角度);

円の端に点が均等に分布しないのはなぜですか?

結果の画像:

ここに画像の説明を入力

class Circle
{
    public Vector2 Origin { get; set; }
    public float Radius { get; set; }
    public List<Vector2> Points { get; set; }

    private Texture2D _texture;

    public Circle(float radius, Vector2 origin, ContentManager content)
    {
        Radius = radius;
        Origin = origin;
        _texture = content.Load<Texture2D>("pixel");
        Points = new List<Vector2>();

        //i = angle
        for (int i = 0; i < 360; i++)
        {
            float x = origin.X + radius * (float)Math.Cos(i);
            float y = origin.Y + radius * (float)Math.Sin(i);
            Points.Add(new Vector2(x, y));
        }
    }

    public void Draw(SpriteBatch spriteBatch)
    {
        for (int i = 0; i < Points.Count; i++)
            spriteBatch.Draw(_texture, Points[i], new Rectangle(0, 0, _texture.Width, _texture.Height), Color.Red);
    }
}
4

2 に答える 2

6

Math.Cos と Math.Sin は、度ではなくラジアンで角度をとります。コードは次のようになります。

float x = origin.X + radius * (float)Math.Cos(i*Math.PI/180.0);
float y = origin.Y + radius * (float)Math.Sin(i*Math.PI/180.0);
于 2013-02-19T14:41:29.173 に答える
1

ポイント:

1) Math.Trig 関数は度ではなくラジアンを使用します。

double2) この種の精度については、の代わりに を使用する方がよいでしょうfloat

3) コンピュータ グラフィックス/ゲームのプロは、Sin や Cos などの高価な関数を使用せず、代わりにBresenham のアルゴリズムのようなインクリメンタルな整数ピクセル指向のアプローチを使用します。これにより、単純な三角関数の数学計算と同等以上の結果が得られ、はるかに高速になります。

于 2013-02-19T14:49:50.877 に答える