圆上物体的均匀分布

编程入门 行业动态 更新时间:2024-10-06 06:52:17
本文介绍了圆上物体的均匀分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在基于两个位置动态创建一个圆;第一个是中心,第二个是半径.然后,我要通过int fillCount = Mathf.RoundToInt(circumference / sizeOfObject);

I'm creating a circle dynamically based on two positions; the first is the centre, and second is the radius. I'm then determining how many of my objects will fit onto the perimeter of the circle by int fillCount = Mathf.RoundToInt(circumference / sizeOfObject);

因此,现在我有了一个圆,我知道圆上可以容纳多少东西,我知道周长,我知道半径,并且我已经拼凑了一个函数,该函数可以找到任意给定点上的Vector3圆圈.

So now I've got a circle, I know how many things will fit on it, I know the circumference, I know the radius, and I've cobbled together a function that will find the Vector3 of any given point on the circle.

我不知道的是如何平均分配每个对象.即,每"n"度放置一个对象.我认为我不必担心电弧重新参数化,还是我要担心?我认为答案就在于通过使用反余弦/正弦来找到放置的程度,但是我不确定,我的数学也不是那么好.

What I can't figure out is how to evenly distribute each object. i.e, place an object every 'n' degrees. I don't think I need to worry about arc-reparameterization, or do I? I think the answer lies in finding the degree of placement by using the inverse cosine/sine, but I'm not sure and my maths isn't that good.

如果任何人有任何意见或建议,我将不胜感激.

If anyone has any input or advice, I'd greatly appreciate it.

推荐答案

如果知道圆中有多少个对象,则可以将360deg除以对象数,以确定每个对象将在圆上放置的角度.由于我们知道圆上的点位于x=r*cos(angle), y=r*sin(angle),因此可以将此Vector2添加到圆的Vector2中心.

If you know how many objects are in the circle, you can divide 360deg by the number of objects to determine the angle on the circle each object will be placed. Since we know the point on a circle is located at x=r*cos(angle), y=r*sin(angle) you can add this Vector2 to the Vector2 center of your circle.

例如,如果您要在圆周围放置3个对象.除以360/3 = 120即可获得角度.每个对象都将彼此放置120度. 选择起点(我们将选择0度), Vector2(r*Mathf.Deg2Rad*cos(0), r*Mathf.Deg2Rad*sin(0)). 下一个物体将在120度,这将是 Vector2(r*Mathf.Deg2Rad*cos(120), r*Mathf.Deg2Rad*sin(120)). 同样,第三个物体将处于240度, Vector2(r*Mathf.Deg2Rad*cos(240), r*Mathf.Deg2Rad*sin(240))

As an example, if you have 3 objects to place around the circle. Get your angle by dividing 360/3 = 120. Each object will be placed 120deg from each other. Pick your starting point (we will pick 0 degrees), Vector2(r*Mathf.Deg2Rad*cos(0), r*Mathf.Deg2Rad*sin(0)). The next object will be at 120deg, which will be Vector2(r*Mathf.Deg2Rad*cos(120), r*Mathf.Deg2Rad*sin(120)). Similarly, the 3rd object will be at 240deg, Vector2(r*Mathf.Deg2Rad*cos(240), r*Mathf.Deg2Rad*sin(240))

更多推荐

圆上物体的均匀分布

本文发布于:2023-11-30 18:34:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651087.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:物体   均匀

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!