找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1955|回复: 3

[分享] Add arc at polyline vertex

[复制链接]

已领礼包: 859个

财富等级: 财运亨通

发表于 2014-6-11 23:27:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
1.    static class Extensions

2.    {

3.        /// <summary>

4.        /// Adds an arc (fillet), if able, at each polyline vertex.

5.        /// </summary>

6.        /// <param name="pline">The instance to which the method applies.</param>

7.        /// <param name="radius">The arc radius.</param>

8.        public static void FilletAll(this Polyline pline, double radius)

9.        {

10.            int j = pline.Closed ? 0 : 1;

11.            for (int i = j; i < pline.NumberOfVertices - j; i++)

12.            {

13.                i += pline.FilletAt(i, radius);

14.            }

15.        }

16.

17.        /// <summary>

18.        /// Adds an arc (fillet) at the specified vertex.

19.        /// </summary>

20.        /// <param name="pline">The instance to which the method applies.</param>

21.        /// <param name="index">The index of the verex.</param>

22.        /// <param name="radius">The arc radius.</param>

23.        /// <returns>1 if the operation succeeded, 0 if it failed.</returns>

24.        public static int FilletAt(this Polyline pline, int index, double radius)

25.        {

26.            int prev = index == 0 && pline.Closed ? pline.NumberOfVertices - 1 : index - 1;

27.            if (pline.GetSegmentType(prev) != SegmentType.Line ||

28.                pline.GetSegmentType(index) != SegmentType.Line)

29.            {

30.                return 0;

31.            }

32.            LineSegment2d seg1 = pline.GetLineSegment2dAt(prev);

33.            LineSegment2d seg2 = pline.GetLineSegment2dAt(index);

34.            Vector2d vec1 = seg1.StartPoint - seg1.EndPoint;

35.            Vector2d vec2 = seg2.EndPoint - seg2.StartPoint;

36.            double angle = vec1.GetAngleTo(vec2) / 2.0;

37.            double dist = radius / Math.Tan(angle);

38.            if (dist > seg1.Length || dist > seg2.Length)

39.            {

40.                return 0;

41.            }

42.            Point2d pt1 = seg1.EndPoint + vec1.GetNormal() * dist;

43.            Point2d pt2 = seg2.StartPoint + vec2.GetNormal() * dist;

44.            double bulge = Math.Tan((Math.PI / 2.0 - angle) / 2.0);

45.            if (Clockwise(seg1.StartPoint, seg1.EndPoint, seg2.EndPoint))

46.            {

47.                bulge = -bulge;

48.            }

49.            pline.AddVertexAt(index, pt1, bulge, 0.0, 0.0);

50.            pline.SetPointAt(index + 1, pt2);

51.            return 1;

52.        }

53.

54.        /// <summary>

55.        /// Evaluates if the points are clockwise.

56.        /// </summary>

57.        /// <param name="p1">First point.</param>

58.        /// <param name="p2">Second point</param>

59.        /// <param name="p3">Third point</param>

60.        /// <returns>True if points are clockwise, False otherwise.</returns>

61.        private static bool Clockwise(Point2d p1, Point2d p2, Point2d p3)

62.        {

63.            return ((p2.X - p1.X) * (p3.Y - p1.Y) - (p2.Y - p1.Y) * (p3.X - p1.X)) < 1e-8;

64.        }

65.    }

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 859个

财富等级: 财运亨通

 楼主| 发表于 2014-6-12 02:27:06 来自手机 | 显示全部楼层
仅仅是两直线段倒角
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 40个

财富等级: 招财进宝

发表于 2014-6-12 21:56:39 | 显示全部楼层
C#好学不?

点评

入门容易,再提高还要学很多 C# 本身的东西  详情 回复 发表于 2014-6-12 22:21
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复

使用道具 举报

已领礼包: 859个

财富等级: 财运亨通

 楼主| 发表于 2014-6-12 22:21:00 | 显示全部楼层
本帖最后由 csharp 于 2014-6-12 22:26 编辑

入门容易,再提高还要学很多 C# 本身的东西,AutoCAD Net API 不再觉得是高不可攀的咚咚,而且比 ARX 好学多了

现在也能看懂一些 ARX 代码了

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-5-22 14:56 , Processed in 0.237125 second(s), 34 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表