|
@@ -83,6 +83,8 @@ namespace HCTools
|
83
|
83
|
return;
|
84
|
84
|
}
|
85
|
85
|
drawSlpeLine();
|
|
86
|
+ MessageBox.Show("绘制完成。");
|
|
87
|
+ this.Close();
|
86
|
88
|
}
|
87
|
89
|
|
88
|
90
|
private void drawSlpeLine()
|
|
@@ -251,85 +253,80 @@ namespace HCTools
|
251
|
253
|
pline.GetClosestPointTo(pl.StartPoint, new Vector3d(0, 0, 1), false))
|
252
|
254
|
).ToList();
|
253
|
255
|
//判断离pl最近等高线与pl高程关系,决定示坡线方向
|
254
|
|
- if (pllist_sorted[0].Elevation > pl.Elevation)
|
|
256
|
+ if(pllist_sorted[0].Elevation == pl.Elevation||
|
|
257
|
+ ((pllist_sorted[0].StartPoint == pllist_sorted[0].EndPoint||pllist_sorted[0].Closed==true)
|
|
258
|
+ && pllist_sorted[0].Length<pl.Length))
|
|
259
|
+ {
|
|
260
|
+ bool flag = inside;
|
|
261
|
+ int i = 0;
|
|
262
|
+ do
|
|
263
|
+ {
|
|
264
|
+ if (pllist_sorted[i].Elevation > pl.Elevation&&
|
|
265
|
+ ((pllist_sorted[i].StartPoint == pllist_sorted[i].EndPoint || pllist_sorted[0].Closed == true)
|
|
266
|
+ && pllist_sorted[i].Length < pl.Length))
|
|
267
|
+ inside = true;
|
|
268
|
+ else
|
|
269
|
+ inside = false;
|
|
270
|
+ i++;
|
|
271
|
+ }
|
|
272
|
+ while (flag!=inside);
|
|
273
|
+ }
|
|
274
|
+ else if (pllist_sorted[0].Elevation > pl.Elevation)
|
255
|
275
|
inside = true;
|
256
|
276
|
else
|
257
|
277
|
inside = false;
|
258
|
278
|
return inside;
|
259
|
279
|
}
|
260
|
280
|
|
261
|
|
- private void markSlopeline(Polyline pl, bool inside,Database db,int blc)
|
|
281
|
+ private void markSlopeline(Polyline pl, bool inside, Database db, int blc)
|
262
|
282
|
{
|
263
|
|
- //拟合多段线上所有点获取一条多段线内近似最长连线
|
264
|
|
- int n = pl.NumberOfVertices;
|
265
|
|
- double sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0;
|
266
|
|
-
|
267
|
|
- for (int i = 0; i < n; i++)
|
268
|
|
- {
|
269
|
|
- Point3d point = pl.GetPoint3dAt(i);
|
270
|
|
- sumX += point.X;
|
271
|
|
- sumY += point.Y;
|
272
|
|
- sumXY += point.X * point.Y;
|
273
|
|
- sumX2 += point.X * point.X;
|
274
|
|
- }
|
275
|
|
- //斜率
|
276
|
|
- double a = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
|
277
|
|
- double b = (sumY - a * sumX) / n;
|
278
|
|
- double x_base1 = pl.Bounds.Value.MaxPoint.X;
|
279
|
|
- double x_base2 = pl.Bounds.Value.MinPoint.X;
|
280
|
|
- Point3d line_pt1 = new Point3d(x_base1, x_base1 * a + b, pl.Elevation);
|
281
|
|
- Point3d line_pt2 = new Point3d(x_base2, x_base2 * a + b, pl.Elevation);
|
282
|
|
- Line fitline = new Line(line_pt1,line_pt2);
|
283
|
|
- Vector3d k = new Vector3d(1, a, 0);
|
284
|
|
- //double xComponent = 1.0;
|
285
|
|
- //double yComponent = b;
|
286
|
|
-
|
287
|
|
- //// 归一化向量,使其成为单位向量。
|
288
|
|
- //double length = Math.Sqrt(xComponent * xComponent + yComponent * yComponent);
|
289
|
|
- //// 防止除以零
|
290
|
|
- //if (Math.Abs(length) > double.Epsilon)
|
291
|
|
- //{
|
292
|
|
- // xComponent /= length;
|
293
|
|
- // yComponent /= length;
|
294
|
|
- //}
|
295
|
|
- //else
|
296
|
|
- //{
|
297
|
|
- // // 处理斜率可能为无穷大或未定义的情况(例如垂直线)
|
298
|
|
- // if (b > 0)
|
299
|
|
- // {
|
300
|
|
- // xComponent = 0;
|
301
|
|
- // yComponent = 1;
|
302
|
|
- // }
|
303
|
|
- // else if (b == 0)
|
304
|
|
- // {
|
305
|
|
- // xComponent = 1;
|
306
|
|
- // yComponent = 0;
|
307
|
|
- // }
|
308
|
|
- // else
|
309
|
|
- // {
|
310
|
|
- // xComponent = 0;
|
311
|
|
- // yComponent = -1;
|
312
|
|
- // }
|
313
|
|
- //}
|
|
283
|
+ //绘制最小外接矩形
|
|
284
|
+ Polyline box = new Polyline();
|
|
285
|
+ Point3d ptMax = pl.Bounds.Value.MaxPoint;
|
|
286
|
+ Point3d ptMin = pl.Bounds.Value.MinPoint;
|
|
287
|
+ box.AddVertexAt(0, new Point2d(ptMin.X, ptMin.Y), 0, 0, 0);
|
|
288
|
+ box.AddVertexAt(1, new Point2d(ptMax.X, ptMin.Y), 0, 0, 0);
|
|
289
|
+ box.AddVertexAt(2, new Point2d(ptMax.X, ptMax.Y), 0, 0, 0);
|
|
290
|
+ box.AddVertexAt(3, new Point2d(ptMin.X, ptMax.Y), 0, 0, 0);
|
|
291
|
+ box.Closed = true;
|
314
|
292
|
|
315
|
|
-
|
316
|
|
- //由于IntersectWith()函数在离原点太远的位置会有误差,所以将需要判断的闭合等高线移动到原点附近
|
317
|
293
|
Vector3d acVec3d_to = pl.StartPoint.GetVectorTo(new Point3d(0, 0, 0));
|
318
|
294
|
var pl_clone = (Polyline)pl.Clone();
|
319
|
|
- var xline_clone = (Line)fitline.Clone();
|
|
295
|
+ var box_clone = (Polyline)box.Clone();
|
320
|
296
|
|
321
|
297
|
pl_clone.TransformBy(Matrix3d.Displacement(acVec3d_to));
|
322
|
|
- xline_clone.TransformBy(Matrix3d.Displacement(acVec3d_to));
|
|
298
|
+ box_clone.TransformBy(Matrix3d.Displacement(acVec3d_to));
|
323
|
299
|
|
324
|
|
- //Vector3d acVec3d_back = pl_clone.StartPoint.GetVectorTo(pl.StartPoint);
|
325
|
300
|
Point3dCollection ptcoll_inter = new Point3dCollection();
|
|
301
|
+ Point3dCollection ptcoll_moveback = new Point3dCollection();
|
326
|
302
|
Point3dCollection ptcoll = new Point3dCollection();
|
327
|
|
- pl_clone.IntersectWith(xline_clone, Intersect.OnBothOperands, ptcoll_inter, IntPtr.Zero, IntPtr.Zero);
|
|
303
|
+ var plane = new Plane(Point3d.Origin, Vector3d.ZAxis);
|
|
304
|
+ pl_clone.IntersectWith(box_clone, Intersect.OnBothOperands, plane, ptcoll_inter, IntPtr.Zero, IntPtr.Zero);
|
328
|
305
|
foreach (Point3d pt in ptcoll_inter)
|
329
|
306
|
{
|
330
|
307
|
Point3d pt_new = pl.GetPointAtParameter(pl_clone.GetParameterAtPoint(pt));
|
331
|
|
- ptcoll.Add(pt_new);
|
|
308
|
+ ptcoll_moveback.Add(pt_new);
|
|
309
|
+ }
|
|
310
|
+
|
|
311
|
+ Point3d pt1 = ptcoll_moveback[0];
|
|
312
|
+ Point3d pt2 = ptcoll_moveback[1];
|
|
313
|
+ double maxDistance = pt1.DistanceTo(pt2);
|
|
314
|
+ for (int i = 0; i < ptcoll_moveback.Count - 1; i++)
|
|
315
|
+ {
|
|
316
|
+ for (int j = i + 1; j < ptcoll_moveback.Count; j++)
|
|
317
|
+ {
|
|
318
|
+ double distance = ptcoll_moveback[i].DistanceTo(ptcoll_moveback[j]);
|
|
319
|
+ if (distance > maxDistance)
|
|
320
|
+ {
|
|
321
|
+ maxDistance = distance;
|
|
322
|
+ pt1 = ptcoll_moveback[i];
|
|
323
|
+ pt2 = ptcoll_moveback[j];
|
|
324
|
+ }
|
|
325
|
+ }
|
332
|
326
|
}
|
|
327
|
+ ptcoll.Add(pt1);
|
|
328
|
+ ptcoll.Add(pt2);
|
|
329
|
+ var k = (ptcoll[0] - ptcoll[1]).GetNormal();
|
333
|
330
|
double spxlength = 1.6;
|
334
|
331
|
if (blc == 500)
|
335
|
332
|
spxlength = spxlength * ((double)500 / 2000);
|