如何从一个点生成一组圆点?
How to generate from one point a set of circle points?
我的情况是我有一个点 Vector3(x,y,z),我需要从该起点生成一个 3D 圆(环),该圆以该点开始并以该点结束它。现在我可以生成一个 vector3 的圆,但我不知道如何只用一个点来生成它。
例如主要点是红色,其他点是黑色:
要定义圆,无论是 2D 还是 3D space,您都需要位于圆上的三个独立点。
否则,有无数(数学上无限)的可能性。
如果你只有一个点,它位于圆(顶部、底部...)的哪个位置?圆的半径是多少?鉴于它是 3D space,它的倾斜度是多少?您不能从单个 (x,y,z,) 点推导出它。
编辑 我在 Paint 中做了一个小的可视化。请注意,这是一个 2D 平面,但同样适用于 3D space(三个点只需要共面,根据定义任何一组三点都是)
编辑 2
这种类型的问题可能最好在与 StackExchange 相关的几何或游戏开发(我怀疑这就是你正在做的)网站上提出,因为这个问题实际上是一个几何问题,而不是编码问题。
编辑 3
我不会为您编写代码,因为 "please write my code" 不是 Whosebug 的意图。
然而,网上有资源可以帮助圆的代数化,你只需要将它放在代码中。
根据this earlier answer on SO, you can find a very detailed explanation of circle-related formulae on this reference page。寻找 "Equation of a Circle from 3 Points (2 dimensions)".
编辑 4,最终编辑
如您所问,您可以根据两个点定义一个圆如果其中一个点是圆的中心点。
然后可以根据这两点之间的距离计算出圆的半径。
从此,有了圆心和圆半径,就可以算出圆上的任意一点了。请参考我上面提到的同一个参考资料link,因为这个页面包含了很多从不同发送的数据中导出圆圈的方法。
编辑5,这次真的是最后的编辑:)
This Whosebug answer 解释你想用代码做什么。它假设你知道中心点和半径,你可以像我上面提到的那样推导出来。
我希望这些信息足以帮助您进一步:)
下面是一个示例,说明如何使用给定的中心向量和半径计算圆点。
这是一个平面,但您可以使用另一个旋转矩阵来旋转它们。
class Program
{
static void Main(string[] args)
{
int n = 22; //the number of points
float radius = 22f;
Vector3 vector = new Vector3(radius, 0, 0); //the vector you keep rotating
Vector3 center = new Vector3(33,33,33); //center of the circle
float angle = (float)Math.PI * 2 / (float)n;
Vector3[] points = new Vector3[n];
Matrix rotation = Matrix.RotationZ(angle);
for (int i = 0; i < n; i++)
{
points[i] = vector + center;
vector.TransformNormal(rotation);
}
}
}
我在项目中使用了托管 directX 框架...不确定您使用的是什么
编辑
旋转和平移问题示意图:
C# 使用 GeoDesy 和 NetTopologySuite。
static Geometry Circle(double lat, double lon, double meters)
{
GeodeticCalculator geoCalc = new GeodeticCalculator(Ellipsoid.WGS84);
GlobalCoordinates start = new GlobalCoordinates(new Angle(lat), new Angle(lon));
int sides = 4;
int degree_unit = 360 / sides;
var c = new List<NetTopologySuite.Geometries.Coordinate>();
for (int i = 0; i < sides; i++)
{
GlobalCoordinates dest = geoCalc.CalculateEndingGlobalCoordinates(start, new Angle(degree_unit * i), meters);
c.Add(new NetTopologySuite.Geometries.Coordinate(dest.Longitude.Degrees, dest.Latitude.Degrees));
}
c.Add(c[0]);
GeometryFactory gc = new GeometryFactory(new PrecisionModel(), 4326);
var box = gc.CreatePolygon(c.ToArray());
var mbc = new MinimumBoundingCircle(box);
return mbc.GetCircle();
}
我的情况是我有一个点 Vector3(x,y,z),我需要从该起点生成一个 3D 圆(环),该圆以该点开始并以该点结束它。现在我可以生成一个 vector3 的圆,但我不知道如何只用一个点来生成它。 例如主要点是红色,其他点是黑色:
要定义圆,无论是 2D 还是 3D space,您都需要位于圆上的三个独立点。
否则,有无数(数学上无限)的可能性。
如果你只有一个点,它位于圆(顶部、底部...)的哪个位置?圆的半径是多少?鉴于它是 3D space,它的倾斜度是多少?您不能从单个 (x,y,z,) 点推导出它。
编辑 我在 Paint 中做了一个小的可视化。请注意,这是一个 2D 平面,但同样适用于 3D space(三个点只需要共面,根据定义任何一组三点都是)
编辑 2
这种类型的问题可能最好在与 StackExchange 相关的几何或游戏开发(我怀疑这就是你正在做的)网站上提出,因为这个问题实际上是一个几何问题,而不是编码问题。
编辑 3
我不会为您编写代码,因为 "please write my code" 不是 Whosebug 的意图。
然而,网上有资源可以帮助圆的代数化,你只需要将它放在代码中。
根据this earlier answer on SO, you can find a very detailed explanation of circle-related formulae on this reference page。寻找 "Equation of a Circle from 3 Points (2 dimensions)".
编辑 4,最终编辑
如您所问,您可以根据两个点定义一个圆如果其中一个点是圆的中心点。
然后可以根据这两点之间的距离计算出圆的半径。
从此,有了圆心和圆半径,就可以算出圆上的任意一点了。请参考我上面提到的同一个参考资料link,因为这个页面包含了很多从不同发送的数据中导出圆圈的方法。
编辑5,这次真的是最后的编辑:)
This Whosebug answer 解释你想用代码做什么。它假设你知道中心点和半径,你可以像我上面提到的那样推导出来。
我希望这些信息足以帮助您进一步:)
下面是一个示例,说明如何使用给定的中心向量和半径计算圆点。
这是一个平面,但您可以使用另一个旋转矩阵来旋转它们。
class Program
{
static void Main(string[] args)
{
int n = 22; //the number of points
float radius = 22f;
Vector3 vector = new Vector3(radius, 0, 0); //the vector you keep rotating
Vector3 center = new Vector3(33,33,33); //center of the circle
float angle = (float)Math.PI * 2 / (float)n;
Vector3[] points = new Vector3[n];
Matrix rotation = Matrix.RotationZ(angle);
for (int i = 0; i < n; i++)
{
points[i] = vector + center;
vector.TransformNormal(rotation);
}
}
}
我在项目中使用了托管 directX 框架...不确定您使用的是什么
编辑
旋转和平移问题示意图:
C# 使用 GeoDesy 和 NetTopologySuite。
static Geometry Circle(double lat, double lon, double meters)
{
GeodeticCalculator geoCalc = new GeodeticCalculator(Ellipsoid.WGS84);
GlobalCoordinates start = new GlobalCoordinates(new Angle(lat), new Angle(lon));
int sides = 4;
int degree_unit = 360 / sides;
var c = new List<NetTopologySuite.Geometries.Coordinate>();
for (int i = 0; i < sides; i++)
{
GlobalCoordinates dest = geoCalc.CalculateEndingGlobalCoordinates(start, new Angle(degree_unit * i), meters);
c.Add(new NetTopologySuite.Geometries.Coordinate(dest.Longitude.Degrees, dest.Latitude.Degrees));
}
c.Add(c[0]);
GeometryFactory gc = new GeometryFactory(new PrecisionModel(), 4326);
var box = gc.CreatePolygon(c.ToArray());
var mbc = new MinimumBoundingCircle(box);
return mbc.GetCircle();
}