您好,如果您的三维线是多节点的话,您也可以参考下这个:
private GeoPoint3D nextPoint3D(GeoLine3D geoLine3D, GeoPoint3D startPoint3D, double distance)
{
//geoLine3D:三维线
Point3Ds point3Ds = geoLine3D[0];
//p1:起始点
GeoPoint3D p1 = startPoint3D;
//requestDistance:经过距离
double requestDistance = distance;
double distance1 = 0;
int startPointPosition = 0;
//检查p1在三维线上的具体位置
for(int i = 1; i < point3Ds.Count; i++)
{
GeoPoint3D geoPoint3DStart = new GeoPoint3D(point3Ds[i - 1]);
GeoPoint3D geoPoint3DEnd = new GeoPoint3D(point3Ds[i]);
if (Geometrist.Distance(p1, geoPoint3DStart) + Geometrist.Distance(p1, geoPoint3DEnd) == Geometrist.Distance(geoPoint3DStart, geoPoint3DEnd))
{
distance1 = Geometrist.Distance(p1, geoPoint3DStart);
break;
}else
{
startPointPosition=i;
}
}
//p1不在三维线上,返回null
if(startPointPosition == point3Ds.Count - 1)
{
MessageBox.Show("start point not at given line!");
return null;
}
//计算结果点
requestDistance = requestDistance + distance1;
for (int i = startPointPosition+1; i < point3Ds.Count; i++)
{
GeoPoint3D geoPoint3DStart = new GeoPoint3D(point3Ds[i - 1]);
GeoPoint3D geoPoint3DEnd = new GeoPoint3D(point3Ds[i]);
requestDistance = requestDistance - Geometrist.Distance(geoPoint3DStart, geoPoint3DEnd);
if (requestDistance<0)
{
double requestDistanceRate = Math.Abs(requestDistance) / Geometrist.Distance(geoPoint3DStart, geoPoint3DEnd);
double x2 = geoPoint3DEnd.X - (geoPoint3DEnd.X - geoPoint3DStart.X) * requestDistanceRate;
double y2 = geoPoint3DEnd.Y - (geoPoint3DEnd.Y - geoPoint3DStart.Y) * requestDistanceRate;
double z2 = geoPoint3DEnd.Z - (geoPoint3DEnd.Z - geoPoint3DStart.Z) * requestDistanceRate;
GeoPoint3D p2 = new GeoPoint3D(x2, y2, z2);
return p2;
}
}
//距离超出线的长度,返回null
MessageBox.Show("Out of range!");
return null;
}