- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
http://www.cnblogs.com/milian/p/3315000.html
求中点坐标:
- /// <summary>
- /// 中点
- /// </summary>
- /// <param name="StartPoint">起点</param>
- /// <param name="EndPoint">终点</param>
- /// <returns></returns>
- public Point3d Midpoint(Point3d StartPoint, Point3d EndPoint)
- {
- Double x = (StartPoint.X + EndPoint.X)/2;
- Double y = (StartPoint.Y + EndPoint.Y) / 2;
- Double z = (StartPoint.Z + EndPoint.Z) / 2;
- return new Point3d(x, y, z);
- }
复制代码 求点到直线的距离:
- /// <summary>
- /// 获得空间点到空间线段的垂直距离
- /// </summary>
- /// <param name="line">直线</param>
- /// <param name="pt">空间的点</param>
- /// <param name="Decimal">小数位数</param>
- /// <returns>点到直线垂直距离</returns>
- public Double Distance(Line line, Point3d pt, Int16 Decimal)
- {
- Double t;
- if (line != null)
- {
- Point3d StartPoint = line.StartPoint;
- Point3d EndPoint = line.EndPoint;
- //直线方向向量
- Point3d dir = new Point3d(StartPoint.X - EndPoint.X, StartPoint.Y - EndPoint.Y, StartPoint.Z - EndPoint.Z);
- //过点且与直线垂直的平面
- t = -(Double)(dir.X * (StartPoint.X - pt.X) + dir.Y * (StartPoint.Y - pt.Y) + dir.Z * (StartPoint.Z - pt.Z)) / (dir.X * dir.X + dir.Y * dir.Y + dir.Z * dir.Z);
- //过点的垂直于直线的平面与该直线的交点
- Point3d fp = new Point3d(StartPoint.X + dir.X * t, StartPoint.Y + dir.Y * t, StartPoint.Z + dir.Z * t);
- return Distance(pt, fp, Decimal);
- }
- else
- {
- return 0;
- }
- }
复制代码 判断两条直线是否重合:
- /// <summary>
- /// 判断两条直线是否重合
- /// </summary>
- /// <param name="line1">线1</param>
- /// <param name="line2">线2</param>
- /// <param name="allowance">容差</param>
- /// <returns></returns>
- public Boolean Coincide(Line line1, Line line2, Double allowance)
- {
- LineSegment3d l1 = new LineSegment3d(line1.StartPoint, line1.EndPoint);
- LineSegment3d l2 = new LineSegment3d(line2.StartPoint, line2.EndPoint);
- Tolerance tol = new Tolerance(allowance, allowance);
- return l1.IsColinearTo(l2, tol);
- }
复制代码 判断点是否在直线上
- /// <summary>
- /// 判断点是否在直线上
- /// </summary>
- /// <param name="line">直线</param>
- /// <param name="point1">点</param>
- /// <param name="allowance">容差</param>
- /// <returns></returns>
- public Boolean Coincide(Line line, Point3d point1, Double allowance)
- {
- Point3d p1 = line.StartPoint;
- Point3d p2 = line.EndPoint;
- //叉积是否为allowance,判断是否在同一直线上
- if (Math.Abs((p1.X - point1.X) * (p2.Y - point1.Y) - (p2.X - point1.X) * (p1.Y - point1.Y)) < allowance)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
复制代码 |
|