使用现有的高度和宽度大小从中心点创建一个矩形
Creating a rectangle from center point with existing height and width size
我正在尝试从中心点创建一个 10 x 10 的矩形。我发现现有代码通过其中心点创建一个矩形,但用户必须通过选择对角来给出大小。我想用 10 x 10 的已知尺寸替换手动部分。用户选择一个点,然后从该中心点创建一个 10 x 10 的矩形。
这是我找到的现有代码:
(defun C:CENRECT ( / pt1 ptc vec)
(setq pt1 (getpoint "\nSpecify the center point: "))
(setq ptc (getpoint pt1 "\nSpecify the corner point: "))
(setq vec (mapcar '- ptc pt1))
(entmake
(list
'(000 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(090 . 4)
'(070 . 1)
(cons 010 (trans (mapcar '+ pt1 (list (-(car vec))(+(cadr vec))(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (+(car vec))(cadr vec)(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (+(car vec))(-(cadr vec))(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (-(car vec))(-(cadr vec))(caddr vec))) 1 0))
(cons 210 (trans '(0.0 0.0 1.0) 1 0 T))
)
)
(redraw)
(princ)
)
我在这里尝试添加已知的 10 x 10 尺寸,而不是让用户手动选择尺寸。
(defun C:test ( / pt1 ptc vec len wid)
(setq pt1 (getpoint "\nSpecify the center point: "))
**(setq len 10)
(setq wid 10)**
(setq ptc (getpoint pt1 **len wid**))
(setq vec (mapcar '- ptc pt1))
(entmake
(list
'(000 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(090 . 4)
'(070 . 1)
(cons 010 (trans (mapcar '+ pt1 (list (-(car vec))(+(cadr vec))(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (+(car vec))(cadr vec)(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (+(car vec))(-(cadr vec))(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (-(car vec))(-(cadr vec))(caddr vec))) 1 0))
(cons 210 (trans '(0.0 0.0 1.0) 1 0 T))
)
)
(redraw)
(princ)
)
我收到参数过多的错误。需要弄清楚如何给出 10 x 10 的对角而不是用户做的。
(setq pt1 (getpoint "\nSpecify the center point: "))
(setq len 10)
(setq wid 10)
(setq vec (list len wid 0 ))
(entmake......
)
应该可以。
由于您提前知道生成的矩形的固定尺寸,因此代码可以简化为以下内容:
(defun c:cenrect ( / c z )
(setq z (trans '(0 0 1) 1 0 t))
(if (setq c (getpoint "\nSpecify center: "))
(entmake
(list
'(000 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(090 . 4)
'(070 . 1)
(cons 010 (trans (mapcar '+ c '(-5 -5)) 1 z))
(cons 010 (trans (mapcar '+ c '( 5 -5)) 1 z))
(cons 010 (trans (mapcar '+ c '( 5 5)) 1 z))
(cons 010 (trans (mapcar '+ c '(-5 5)) 1 z))
(cons 210 z)
)
)
)
(princ)
)
此处,折线顶点是相对于提供的中心点(相对于活动 UCS)计算的,然后这些顶点相对于对象坐标系 (OCS) 进行变换。
我正在尝试从中心点创建一个 10 x 10 的矩形。我发现现有代码通过其中心点创建一个矩形,但用户必须通过选择对角来给出大小。我想用 10 x 10 的已知尺寸替换手动部分。用户选择一个点,然后从该中心点创建一个 10 x 10 的矩形。
这是我找到的现有代码:
(defun C:CENRECT ( / pt1 ptc vec)
(setq pt1 (getpoint "\nSpecify the center point: "))
(setq ptc (getpoint pt1 "\nSpecify the corner point: "))
(setq vec (mapcar '- ptc pt1))
(entmake
(list
'(000 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(090 . 4)
'(070 . 1)
(cons 010 (trans (mapcar '+ pt1 (list (-(car vec))(+(cadr vec))(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (+(car vec))(cadr vec)(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (+(car vec))(-(cadr vec))(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (-(car vec))(-(cadr vec))(caddr vec))) 1 0))
(cons 210 (trans '(0.0 0.0 1.0) 1 0 T))
)
)
(redraw)
(princ)
)
我在这里尝试添加已知的 10 x 10 尺寸,而不是让用户手动选择尺寸。
(defun C:test ( / pt1 ptc vec len wid)
(setq pt1 (getpoint "\nSpecify the center point: "))
**(setq len 10)
(setq wid 10)**
(setq ptc (getpoint pt1 **len wid**))
(setq vec (mapcar '- ptc pt1))
(entmake
(list
'(000 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(090 . 4)
'(070 . 1)
(cons 010 (trans (mapcar '+ pt1 (list (-(car vec))(+(cadr vec))(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (+(car vec))(cadr vec)(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (+(car vec))(-(cadr vec))(caddr vec))) 1 0))
(cons 010 (trans (mapcar '+ pt1 (list (-(car vec))(-(cadr vec))(caddr vec))) 1 0))
(cons 210 (trans '(0.0 0.0 1.0) 1 0 T))
)
)
(redraw)
(princ)
)
我收到参数过多的错误。需要弄清楚如何给出 10 x 10 的对角而不是用户做的。
(setq pt1 (getpoint "\nSpecify the center point: "))
(setq len 10)
(setq wid 10)
(setq vec (list len wid 0 ))
(entmake......
)
应该可以。
由于您提前知道生成的矩形的固定尺寸,因此代码可以简化为以下内容:
(defun c:cenrect ( / c z )
(setq z (trans '(0 0 1) 1 0 t))
(if (setq c (getpoint "\nSpecify center: "))
(entmake
(list
'(000 . "LWPOLYLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbPolyline")
'(090 . 4)
'(070 . 1)
(cons 010 (trans (mapcar '+ c '(-5 -5)) 1 z))
(cons 010 (trans (mapcar '+ c '( 5 -5)) 1 z))
(cons 010 (trans (mapcar '+ c '( 5 5)) 1 z))
(cons 010 (trans (mapcar '+ c '(-5 5)) 1 z))
(cons 210 z)
)
)
)
(princ)
)
此处,折线顶点是相对于提供的中心点(相对于活动 UCS)计算的,然后这些顶点相对于对象坐标系 (OCS) 进行变换。