明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 7290|回复: 6

如何画矩形?

[复制链接]
发表于 2009-9-29 14:32 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2009-9-30 09:43 | 显示全部楼层

不知道你想说什么,是不是说点两个点,这两个点是矩形的长和宽的中心点,而且长和宽的尺寸均可以输入?

如果是这样你永远也写不出来,因为数学模型就不成立,如下图所示

图中pt1和pt2是所点的两点,S是两点间的长度,所输入的长和宽的尺寸分别为2A和2B,即半个长度A和半个宽度B和S构成一个三角形,一个三角形的三条边长均已知怎么能保证夹角P是个直角呢,用你的平面几何知识算一下这个角度的公式吧,这明显是一个无法完成的任务,而P只要不是直角你得出来的肯定是一个平行四边形,哈哈

本帖子中包含更多资源

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

x
 楼主| 发表于 2009-10-10 11:59 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2009-10-10 17:24 | 显示全部楼层
  1. Public Function DrawRectang(RecHalfWidth As Double) As Object
  2.     Dim Pt1 As Variant
  3.     Dim Pt2 As Variant
  4.     Dim RectRotation As Double
  5.     Dim objPolyline As Object
  6.     Dim RectangPoint(0 To 11) As Double
  7.    
  8.     ' 获得第一点Pt1
  9.     Pt1 = ThisDrawing.Utility.GetPoint(, "指定起始点")
  10.     ' 获得第二点Pt2
  11.     Pt2 = ThisDrawing.Utility.GetPoint(Pt1, "指定结束点")
  12.     ' 得到两点构成直线的的角度值
  13.     RectRotation = Atn((Pt2(1) - Pt1(1)) / (Pt2(0) - Pt1(0)))
  14.    
  15.     ' 根据Pt1、Pt2两点计算矩形各顶点坐标
  16.     RectangPoint(0) = Pt1(0) - RecHalfWidth * Sin(RectRotation)
  17.     RectangPoint(1) = Pt1(1) + RecHalfWidth * Cos(RectRotation)
  18.    
  19.     RectangPoint(3) = Pt1(0) + RecHalfWidth * Sin(RectRotation)
  20.     RectangPoint(4) = Pt1(1) - RecHalfWidth * Cos(RectRotation)
  21.    
  22.     RectangPoint(6) = Pt2(0) + RecHalfWidth * Sin(RectRotation)
  23.     RectangPoint(7) = Pt2(1) - RecHalfWidth * Cos(RectRotation)
  24.    
  25.     RectangPoint(9) = Pt2(0) - RecHalfWidth * Sin(RectRotation)
  26.     RectangPoint(10) = Pt2(1) + RecHalfWidth * Cos(RectRotation)
  27.    
  28.     Set objPolyline = ThisDrawing.ModelSpace.AddPolyline(RectangPoint)
  29.     objPolyline.Closed = True
  30.    
  31.     Set DrawRectang = objPolyline
  32. End Function

 楼主| 发表于 2009-10-10 19:33 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2013-4-11 17:14 | 显示全部楼层
本帖最后由 crazylsp 于 2013-4-11 17:26 编辑

谢谢wlong的程序,不过画出是个旋转角度的不过这样也好,随机的美感,半宽其实不用设,可由pt1,pt2两个点计算出
发表于 2019-1-25 19:41 | 显示全部楼层
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-20 15:43 , Processed in 0.185946 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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