加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 圆角上的点不均匀间隔

发布时间:2020-12-16 01:53:07 所属栏目:百科 来源:网络整理
导读:参见英文答案 Finding Points On Perimeter Of a Circle????????????????????????????????????1个 鉴于: x = originX radius * Cos(角度); y = originY radius * Sin(角度); 为什么这些点不能均匀分布在圆的边缘? 结果图: class Circle{ public Vector2 O
参见英文答案 > Finding Points On Perimeter Of a Circle????????????????????????????????????1个
鉴于:

x = originX radius * Cos(角度);

y = originY radius * 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,_texture.Width,_texture.Height),Color.Red);
    }
}

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读