TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: bilanšikur on October 22, 2012, 02:14:17 PM

Title: How to calculate mirrored point
Post by: bilanšikur on October 22, 2012, 02:14:17 PM
Dear all,

Maybe someone would like to help?

I am trying to create a routine in vlisp that would return the insertion point of a mirrored block, without using the mirror command and without mirroring the block. I just need to know where the mirrored insertionpoint would be. The arguments would be the first point on a mirror line, the second point on a mirror line, the third to select 1 block. It would return something like '(2454.78 951.243 0.0).

My attempt: start with something like (vlax-curve-getClosestPointto obj pnt) and get the closest point on the mirror line calculated from the blocks insertion point. Now I have 2 points, pt1 and pt2. Next I need to calculate the mirrored position; should I go with (polar pnt ang dist)?  Because I have pt1 (block insertionpoint) and pt2 (closest point on curve) I then also have the distance and the angle. I am just stuck how to put it together in short way.

Has this anything to do with matrix calculation? I seen that term often... but never really used any of it.

Anyone got some ideas where to start? Thanks already! Yarik.
Title: Re: How to calculate mirrored point
Post by: BlackBox on October 22, 2012, 02:44:25 PM
Wouldn't it be simpler to instead copy the block in place, set the copied block's Visible (http://entercad.ru/acadauto.en/index.html?page=idh_visible.htm) Property to False, mirror the copied block, extract the insertion point, then delete the block?  :?
Title: Re: How to calculate mirrored point
Post by: bilanšikur on October 23, 2012, 01:49:43 AM
Thank you for the repy. Maybe it would, but that is a cheat.

This would be my code:

Code: [Select]
(defun miPt (/ mlent ent entl nm la pt1 pt2 dist ang pt3)

  (setq mlent (car (entsel "\nSelect mirror line: "))
ent   (car (entsel "\nSelect object:"))
  )
  (setq entl (entget ent))
  (setq pt1 (cdr (assoc 10 entl))
  )

  (setq pt2 (vlax-curve-getClosestPointTo mlent pt1))

  (setq dist (distance pt1 pt2)
ang  (angle pt2 pt1)
  )

  (setq pt3 (polar pt2 (+ ang pi) dist))

)


It returns exactly what I need. Would there be a faster / shorter way?
Title: Re: How to calculate mirrored point
Post by: Stefan on October 23, 2012, 03:04:24 AM
For 2D space
Code - Auto/Visual Lisp: [Select]
  1. (defun mirr_point (p1 p2 b)
  2.  (polar p1 (- (* 2 (angle p1 p2)) (angle p1 b)) (distance p1 b))
  3. )
3D space
Code - Auto/Visual Lisp: [Select]
  1. (defun mirr_point (p1 p2 b)
  2.   ((lambda (p z)
  3.      (list (car p) (cadr p) z)
  4.    )
  5.     (polar p1 (- (* 2 (angle p1 p2)) (angle p1 b)) (distance p1 (list (car b) (cadr b))))
  6.     (caddr b)
  7.   )
  8. )
p1 and p2 - points on mirror line
b - point to be mirrored
Title: Re: How to calculate mirrored point
Post by: Lee Mac on October 23, 2012, 07:26:24 AM
Another, using trans:
Code - Auto/Visual Lisp: [Select]
  1. ;; Reflect  -  Lee Mac
  2. ;; Returns the point obtained by reflecting 'pt' in the axis defined by points p1 & p2.
  3.  
  4. (defun LM:reflect ( pt p1 p2 / ax )
  5.     (setq ax (mapcar '- p1 p2)
  6.           p1 (trans p1 0 ax)
  7.           pt (trans pt 0 ax)
  8.     )
  9.     (trans (cons (- (+ (car p1) (car p1)) (car pt)) (cdr pt)) ax 0)
  10. )
Title: Re: How to calculate mirrored point
Post by: Lee Mac on October 23, 2012, 07:46:39 AM
Has this anything to do with matrix calculation? I seen that term often... but never really used any of it.

Consider these (http://lee-mac.com/matrixtransformationfunctions.html) old functions if you wish to use a matrix  :-)