我有一个立方体的点云。我用random()创建了它,所以所有的x,y,z点都在0和1之间。我这样创建了多维数据集。
import numpy as np
import open3d
import random
listPoints = []
for i in range(10000):
x = random.random()
y = random.random()
z = random.random()
listPoints.append([x,y,z])
arrayPoints = np.asarray(listPoints)
point_cloud = open3d.PointCloud()
point_cloud.points = open3d.Vector3dVector(arrayPoints)
open3d.draw_geometries([point_cloud])
现在,我想获得对角线上的点。我现在如何获取与点垂直的点。我需要将一些度数乘以度,但是我不知道该怎么做。我用来垂直于立方体中间的代码:(Y为0.5,因此我将其保持静态并检查所有具有0.5 Y值的点)
listPoints2 = []
minimumY = 0.5 - 0.02
maximumY = 0.5 + 0.02
for i in range(10000):
if(listPoints[i][1] < maximumY and listPoints[i][1] > minimumY):
listPoints2.append([listPoints[i][0],listPoints[i][1],listPoints[i][2]])
arrayPoints2 = np.asarray(listPoints2)
point_cloud2 = open3d.PointCloud()
point_cloud2.points = open3d.Vector3dVector(arrayPoints2)
open3d.draw_geometries([point_cloud2])
我的最终输出带有垂直点。我希望它像对角线一样倾斜。
我应该将我的值乘以什么以获得对角线?
答案 0 :(得分:0)
您需要的是计算点到轴的垂直距离,请参见:
由此,您只需测试所有点是否足够接近立方体的4个对角线。在 C ++ (抱歉,不是Python编码器)中,它看起来像这样:
import { PortalInjector } from '@angular/cdk/portal';
...
const tokens = new WeakMap();
tokens.set(MULTI_SELECT_OVERLAY_DATA, {
options: this.listOptions,
});
const injector = new PortalInjector(this.injector, tokens);
...
const multiSelectPortal = new ComponentPortal(MultiSelectOverlayComponent, null, injector);
所以我声明了4个轴//---------------------------------------------------------------------------
const int n=10000; // points
const int n3=n+n+n; // points*dimensions
double pnt[n3]; // points x,y,z ...
DWORD col[n]; // colors rgba, ...
//---------------------------------------------------------------------------
double distance_point_axis(double *p,double *p0,double *dp)
{
int i;
double l,d,q[3];
for (i=0;i<3;i++) q[i]=p[i]-p0[i]; // q = p-p0
for (l=0.0,i=0;i<3;i++) l+=dp[i]*dp[i]; // l = |dp|^2
for (d=0.0,i=0;i<3;i++) d+=q[i]*dp[i]; // d = dot(q,dp)
if (l<1e-10) d=0.0; else d/=l; // d = dot(q,dp)/|dp|^2
for (i=0;i<3;i++) q[i]-=dp[i]*d; // q=q-dp*dot(q,dp)/|dp|^2
for (l=0.0,i=0;i<3;i++) l+=q[i]*q[i]; l=sqrt(l); // l = |q|
return l;
}
//---------------------------------------------------------------------------
void pnt_init()
{
Randomize();
int i,i3,j;
double r=0.1; // radius of diagonals cylinders
double diag[4*6]=
{
// p0 dp
0.0,0.0,0.0, +1.0,+1.0,+1.0, // diagonal 1
0.0,1.0,0.0, +1.0,-1.0,+1.0, // diagonal 2
1.0,0.0,0.0, -1.0,+1.0,+1.0, // diagonal 3
1.0,1.0,0.0, -1.0,-1.0,+1.0, // diagonal 4
};
// compute some uniformly random points <0,1>
for (i3=0;i3<n3;i3++) pnt[i3]=Random();
// compute color
for (i=0,i3=0;i<n;i++,i3+=3)
{
// graysh
col[i]=0x00303030;
// diagonals
j=0;
if (distance_point_axis(pnt+i3,diag+j+0,diag+j+3)<r) col[i]|=0x00FF0000; j+=6;
if (distance_point_axis(pnt+i3,diag+j+0,diag+j+3)<r) col[i]|=0x0000FF00; j+=6;
if (distance_point_axis(pnt+i3,diag+j+0,diag+j+3)<r) col[i]|=0x000000FF; j+=6;
if (distance_point_axis(pnt+i3,diag+j+0,diag+j+3)<r) col[i]|=0x00FF00FF; j+=6;
}
}
//---------------------------------------------------------------------------
void gl_draw()
{
int i,i3;
static double ang=0.0; ang+=2.5; if (ang>360.0) ang-=360.0;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-0.5,-0.5,-5.0);
glRotatef(ang,0.5,0.5,0.5);
// render points froma list
glBegin(GL_POINTS);
for (i=0,i3=0;i<n;i++,i3+=3)
{
glColor4ubv((BYTE*)(col+i));
glVertex3dv(pnt+i3);
}
glEnd();
// glFlush();
glFinish();
SwapBuffers(hdc);
}
//---------------------------------------------------------------------------
(起点和方向向量),然后设置每个点的颜色,使其接近预定义的RGB颜色...
此处预览:
和GIF动画:
如果您想要更简单的东西,那么立方体的主对角线就是
diag[4*6]
只需测试
x = y = z
对于每个点...其他对角线仅是镜像,因此只需将镜像的fabs(x-y)+fabs(x-z)+fabs(y-z) <= 1e-2
替换为coordinate