It looks, if I'm reading your code correctly, as though the answer to my question in Post 2 is "always the vertical line."
There are ways to do that without all those angle & trigonometric calculations. You can also omit asking for the corners beforehand, since the RECTANGLE command will do that. That command makes a Polyline, always drawn with one of the horizontal edges first. Even though it is not "curved," it counts as one of the classes of "curve" objects in (vlax-curve-...) functions. For the purpose of those functions, a Polyline has Parameter values of integers at its vertices, starting with Parameter 0 at the beginning. So you can do this, which uses no variables at all:
(vl-load-com); if not already loaded
(defun C:RD2 ()
(command
"_.rectangle" pause pause ; it will ask for the corners
"_.line"
"_none" (vlax-curve-getPointAtParam (entlast) 0.5); midpoint of 1st segment
"_none" (vlax-curve-getPointAtParam (entlast) 2.5); midpoint of 3rd segment
"" ; end Line
); command
); defun
If you want the horizontal mid-line instead, change the 0.5 to 1.5, and change the 2.5 to 3.5.
But if you need the corners saved for some other purpose, you can get the lengths of the sides much more concisely:
(DEFUN C:RD()
(SETQ
P1 (GETPOINT "\n PICK IST CORNER: ")
P2 (GETCORNER P1 "\n PICK OPPOSITE CORNER: ")
delta (mapcar '- p2 p1); XYZ difference between corners
; CA (ABS (cadr delta)); Y-direction distance [not needed]
CCA (ABS (car delta)); X-direction distance
); setq
(COMMAND
"RECTANGLE" P1 P2
"LINE"
"_none" (POLAR P1 (if (minusp (car delta)) pi 0) (/ CCA 2))
"_none" (POLAR P2 (if (minusp (car delta)) 0 pi) (/ CCA 2))
""
); command
)
Some of your variables are never used [P3, CRT, FI]. If you do need the middle of the rectangle [P3], here's a shorter way to calculate it:
(mapcar '/ (mapcar '+ p1 p2) '(2 2 2))
Kent Cooper, AIA