(defun DTR (ang)(* pi (/ ang 180.0)))
Sample A:
(setq P1 '(200.0 300.0) P2 '(400.0 400.0))
(setq P3 (list (+ (car P1) 30) (+ (cadr P1) 20))) => (230.0 320.0)
(setq P4 (list (+ (car P1) 90) (- (cadr P2) 53))) => (290.0 347.0)
(setq P5 (list (- (car P2) 40) (- (cadr P2) 35))) => (360.0 365.0)
Sample B:
(setq A1 310);angle
(setq P1 '(200.0 300.0) P2 '(111.07,94.84)) ; (rounded)
(setq P3 (polar (polar P1 (DTR (- 310 90)) 30) (DTR 310) 20)) => (189.874 265.395)
...
Maybe it's not simpler, but sure is more elegant...Thanks for answer, I tried with the change of UCS but it is a too slow operation if repeated many many times. Have you an example with matrix?
You could use matrix with rotated coordinate system and then multiply each vector of p3, p4, p5 with it to get new coordinates... You can also acquire this result by setting UCS for Sample A rectangle (translated WCS to UCS at p1) and use (trans) function to translate point coordinates from WCS to UCS at p1 - you use (trans p 0 1) and finally from those resulting points in UCS (translated) to WCS, but previously set new Sample B UCS (rotated) - you then use (trans p-"sampleA-previousUCS(translated)" 1-"sampleB-UCS(rotated)" 0)...
(defun test ( / oldsnap x y pt1 pt2 ang)
(setq oldsnap (getvar 'osmode))
(setq pt1 (getpoint "pick pt1"))
(setq pt2 (getpoint "Pick pt2"))
(setq ang (angle pt1 pt2))
(setq x (getreal "dist X"))
(setq y (getreal "dist Y"))
(setq pt2 (polar pt1 ang x))
(setq pt2 (polar pt2 (+ ang (/ pi 2)) y))
(setvar 'osmode 0)
(command "point" pt2)
(setvar 'osmode oldsnap)
)
(test)
(setq
orig '(200.0 300.0 0.0) ; p1
ang (/ (* 11.0 pi) 9.0) ; 220 deg, ccw (trigonometric)
)
(defun TransByAngOff (OrgPnt RotAng OffStX OffStY)
(polar (polar OrgPnt RotAng OffStX) (+ RotAng (/ pi 2)) OffStY)
)
(TransByAngOff orig ang 30 20) => (189.874 265.395 0.0)
You know what? The polar approach is the most simple and direct solution.Thanks for your time, If I know offset as in my drawing image for P3, are you saying that is better this approach?
What I'd change, is the input convention. OffStX and OffStY are just the coordinates of the current point relative to P1.
IMO, using points in WCS is better and if you really need the relative coordinates, you can always use (mapcar '- p o).
In this case, your function could be:
o - origin (P1 in your case)
p - point, in WCS
a - rotation angleCode - Auto/Visual Lisp: [Select]
(setq P1 '(200.0 300.0))
(setq ang (/ (* 11.0 pi) 9.0))
(defun TransByPntAng (o p a)
(polar o (+ (angle o p) a) (distance o p))
)
(TransByPntAng P1 (mapcar '+ '(30 20 0) P1) ang) => (189.874 265.395)
Also…Thanks, CAL is not an option for BricsCAD :(
with:
(setq p1 '(200.0 300.0))
(setq p5 '(360.0 365.0))
(setq a 310.0)
(setq p5r (cal "rot (p5,p1,a-90)"))
(119.214 147.361 0.0)
_$
;|TEXTBOX returns the points that enclose the text relative to 0,0. So after
*translating* the points returned to be relative to the insertion point of
the text, I have done this for 2d purposes as far as rotation is concerned.
--
-Jason
|;
Jason Piercey Apr 9 2002, 7:40 pm
;Rotate a point or list of points about a base point
;ArgLst '([Base point] [List of points] [Radian angle])
(defun PtRotate (ArgLst / BasePt PtLst Ang d a)
(mapcar 'set '(BasePt PtLst Ang) ArgLst)
(mapcar
'(lambda (x)
(setq d (distance BasePt x)
a (+ (angle BasePt x) Ang)
)
(polar BasePt a d)
)
PtLst
)
)
Oldie:Code: [Select];|TEXTBOX returns the points that enclose the text relative to 0,0. So after
*translating* the points returned to be relative to the insertion point of
the text, I have done this for 2d purposes as far as rotation is concerned.
--
-Jason
|;
Jason Piercey Apr 9 2002, 7:40 pm
;Rotate a point or list of points about a base point
;ArgLst '([Base point] [List of points] [Radian angle])
(defun PtRotate (ArgLst / BasePt PtLst Ang d a)
(mapcar 'set '(BasePt PtLst Ang) ArgLst)
(mapcar
'(lambda (x)
(setq d (distance BasePt x)
a (+ (angle BasePt x) Ang)
)
(polar BasePt a d)
)
PtLst
)
)
(defun PtRotate2 (BasePt PtLst Ang / d a)
(mapcar
'(lambda (x)
(setq d (distance BasePt x)
a (+ (angle BasePt x) Ang)
)
(polar BasePt a d)
)
PtLst
)
)
(setq ArgLst (list '(10. 10. 0.) '((20. 20. 0.) (30. 30. 0.) (30. 30. 0.)) (/ pi 2)))
(setq BasePt '(10. 10. 0.) PtLst '((20. 20. 0.) (30. 30. 0.) (30. 30. 0.)) Ang (/ pi 2))
Command: (PtRotate ArgLst) => ((0.0 20.0 0.0) (-10.0 30.0 0.0) (-10.0 30.0 0.0))
Comamnd: (PtRotate2 BasePt PtLst Ang) => ((0.0 20.0 0.0) (-10.0 30.0 0.0) (-10.0 30.0 0.0))