- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 csharp 于 2014-9-2 18:26 编辑
Lisp http://bbs.xdcad.net/forum.php?mod=viewthread&tid=668873
-1 外部,0 边上或者顶点,1 内部
- public static int IsInside(this Point3d pt, Point3dCollection pts)
- {
- double pi = Math.PI;
- double fpi = -pi;
- Point3dCollection npts = new Point3dCollection(pts.Cast<Point3d>().ToArray());
- npts.Add(pts[0]);
- Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
- double tol = 0.0;
- for (int i = 0; i < npts.Count - 1; i++)
- {
- Point3d p1 = npts[i];
- Point3d p2 = npts[i + 1];
- LineSegment3d ln = new LineSegment3d(p1, p2);
- if (ln.IsOn(pt) || pt == p1)
- {
- return 0;
- }
- Vector3d vec1 = pt - p1;
- Vector3d vec2 = pt - p2;
- double an = vec1.AngleOnPlane(plane) - vec2.AngleOnPlane(plane);
- if (an > pi)
- {
- an -= pi;
- }
- else if (an < fpi)
- {
- an += pi;
- }
- tol += an;
- }
- if (Math.Abs(Math.Abs(tol) - pi) < 1e-6)
- {
- return 1;
- }
- else
- {
- return -1;
- }
- }
复制代码 |
|