gpt4 book ai didi

c++ - 通过与多个 3D 平面相交获得最小二乘调整的单线

转载 作者:行者123 更新时间:2023-11-28 07:43:14 26 4
gpt4 key购买 nike

我正在处理许多 3D 平面并为以下情况寻找最小二乘法解决方案。

IF I am having many number of 3D planes knowing only one point and thenormal vector (for eg. O1 and N1), and all those planes intersect eachother and make nearly very close 3d lines, then how to compute theleast square adjusted one single 3d line to represent all thoseintersections.

为了清楚起见,我插入了一张图。

  • 已知:一个点和每个平面的法 vector 。
  • 求:最小二乘拟合单线3d

enter image description here

因为我想用 c++ 做这个,所以我也使用 c++ 标签。

最佳答案

完全未经测试。

如果您从交叉点获取线的方向并得到 Principle Component 会怎么样?

这将为您提供他们前进的方向。然后使用该方向和任意点创建一个平面,将平面相交计算中的所有点投影到平面上,并找到这些投影点的平均点。

使用该平均点和主成分来定义您的线。

有点像...

class Plane
{
public:
Vector3 Point;
Vector3 Normal;

Line Intersect (const Plane &other);

Vector3 Project (const Vector3 &point);
}

class Line
{
public:
Vector3 Point;
Vector3 Direction;

Line (Vector3 point, Vector3 dir);

};

Vector3 PrincipleComponent (const std::vector<Line> &lines)
{
//You could use the covariance matrix to get this but I will try the interative method on wikipedia.
Vector3 p(1,2,3); //a random vector?
static const int c = 10;
for (int i = 0; i < c; ++i)
{
Vector3 t;
for (auto i = lines.begin(); i != lines.end (); ++i)
{
t = t + ((*i).Direction.Dot (p)) * (*i).Direction;
}
t.Normalize();
p = t;
}
return p;
}

int main ()
{
std::vector<Line> LinesFromPlaneIntersections;


Vector3 direction = PrincipleComponent (LinesFromPlaneIntersections);
Plane projplane;
projplane.Normal = direction;
projplane.Point = LinesFromPlaneIntersections[0].Point;

Vector3 meanpoint;
for (auto i = LinesFromPlaneIntersections.begin(); i != LinesFromPlaneIntersections.end (); ++i)
{
meanpoint += projplane.Project ((*i).Point);
}

meanpoint /= LinesFromPlaneIntersections.size ();

Line result (meanpoint,direction);
}

关于c++ - 通过与多个 3D 平面相交获得最小二乘调整的单线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15410788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com