Jump to content

Lee Mac - Geometry function explined


samifox

Recommended Posts

hi

 

learning Lee's geometry functions , starting with Perpendicular-p()

 

what is vxv and and what is the decimal 1e-8 mean?

 

;; Perpendicular-p  -  Lee Mac
;; Returns T if vectors v1,v2 are perpendicular

(defun LM:Perpendicular-p ( v1 v2 )
   (equal 0.0 ([b][color="red"]vxv[/color][/b] v1 v2) [color="red"][b]1e-8[/b][/color])
)

Link to comment
Share on other sites

That function stands for a dot product of 2 vectors (as opposed to a cross product). From Lee's collection:

;; Vector Dot Product  -  Lee Mac
;; Args: u,v - vectors in R^n

(defun vxv ( u v )
   (apply '+ (mapcar '* u v))
)

The 1e-8 is the scientific notation for 10 raised at -8, used to simplify writing of such numbers; its equivalent with:

(expt 10.0 -

Link to comment
Share on other sites

Lee Mac nice coding style simple but works!!

 

still long way to achieve his level :)

Here just to share another method

my version 3-lines cosine

(defun per-p (a b c fuzz)
(equal ( / pi 2)
 ('((d )
    (if
      (equal (abs d) 1. 1e-16)
     0.
     (+ (* 2. (atan 1.)) (atan (/ d (sqrt (- 1. (* d d ))))) ); (* 2. (atan 1.))= (/ pi 2)
     )
    )
   (/ (+ (* a a) (* b b) (-(* c c)))(* 2. a b))
   )
fuzz)
) ;_ end of defun

(per-p 3. 4. 5. 1e-16); T

*EDIT comment removed

Link to comment
Share on other sites

hi

i always treat entites by points, in this function , the expected areguments are vectors, how can i use it? can someonr please post an example?

 

Thanks

S

Link to comment
Share on other sites

Apply in math

Area Formula:

| x1 x2 x3 x4 xn.. |

| \/ \/ \/ \/ \/ |

|. /\ /\ /\ /\ /\ |

| y1 y2 y3 y4 yn.. | .1/2

 

;hanhphuc 07/07/2014
(defun 2d-area (l)
 (abs
   (/ (apply '-
      (mapcar '(lambda (x y)
   (vxv  ; sub function by LEE MAC
     (mapcar '(eval x) l)
     (mapcar '(eval y)
      (append (cdr l) (list (car l)))
     )
   ) ;_ vxv
        ) ;_ end of lambda
       '(car cadr)
       '(cadr car)
      ) ;_ end of mapcar
      ) ;_ end of apply
      2.
   ) ;_ end of /
   
 );_ end of abs
 
) ;_ end of defun

 

;Test:

(2d-area '((0.0 0.0 ) (4.0 0.0 ) (4.0 3.0 )) )

;6.0

Link to comment
Share on other sites

Apply in math

Area Formula:

| x1 x2 x3 x4 xn.. |

| \/ \/ \/ \/ \/ |

|. /\ /\ /\ /\ /\ |

| y1 y2 y3 y4 yn.. | .1/2

 

;hanhphuc 07/07/2014
(defun 2d-area (l)
 (abs
   (/ (apply '-
      (mapcar '(lambda (x y)
   (vxv  ; sub function by LEE MAC
     (mapcar '(eval x) l)
     (mapcar '(eval y)
      (append (cdr l) (list (car l)))
     )
   ) ;_ vxv
        ) ;_ end of lambda
       '(car cadr)
       '(cadr car)
      ) ;_ end of mapcar
      ) ;_ end of apply
      2.
   ) ;_ end of /
   
 );_ end of abs
 
) ;_ end of defun

 

;Test:

(2d-area '((0.0 0.0 ) (4.0 0.0 ) (4.0 3.0 )) )

;6.0

 

sorry i still dont understand...could it be simpler?

Link to comment
Share on other sites

sorry i still dont understand...could it be simpler?

 

hi hope this helps?

 

Area.PNG

 

pls advise if i get you wrong direction, thanx

:)

Edited by hanhphuc
Link to comment
Share on other sites

1e-8 is used to improve comparison of two values where one has more decimal places in its value not returning true

 

V1 = 123.123

v2 = 123.12300003

v1 is not equal to v2 but taking into acount tolerance it is.

Link to comment
Share on other sites

hi hope this helps?

 

Area.PNG

 

pls advise if i get you wrong direction, thanx

:)

 

THANK YOU for the visual explanation, :)

 

vxv() compares the x.y of the 3 given coordinates and multiply and divide their components in order the get the area, that cool!

 

but how its related to passing vectors to a function?

 

Thanks

Shay

Link to comment
Share on other sites

anyone please? just need to know how to pass 2 vectors to Mac Lee's function

 

;; Perpendicular-p  -  Lee Mac
;; Returns T if vectors v1,v2 are perpendicular

(defun LM:Perpendicular-p ( v1 v2 )
   (equal 0.0 (vxv v1 v2) 1e-
)

Link to comment
Share on other sites

As MSasu explained: vxv is dot product

(vxv '(P Q) '(R S)) = P*R + Q*S

 

If a Line A (x1,y1) to B (x2,y2) ,the vector only 2 directions:

(x1-x2 , y1-y2) or (x2-x1 , y2-y1)

 

Example:

assume A to B, delta = '(-3.0 -4.0 )

C to D, delta = '(-4.0 3.0 )

 

meaning : (vxv A-B C-D )

(vxv '(-3.0 -4.0 ) '(-4.0 3.0 ))
; -3*-4 + -4*3 = 12 + -12 = 0.0

 

if we change the C to D direction ,ie= D to C, so delta = '(4.0 -3.0 )

(vxv '(-3.0 -4.0 ) '(4.0 -3.0 ))
; -3*4 + -4*-3 = -12 + 12 = 0.0

still zerop, T

 

p/s: sorry previous picture, the sum label which before AREA result should be indicated as sum1-2 instead of sum, spread sheet explains.

download

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...