samifox Posted July 7, 2014 Share Posted July 7, 2014 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]) ) Quote Link to comment Share on other sites More sharing options...
MSasu Posted July 7, 2014 Share Posted July 7, 2014 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 - Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted July 7, 2014 Share Posted July 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
samifox Posted July 7, 2014 Author Share Posted July 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted July 7, 2014 Share Posted July 7, 2014 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 Quote Link to comment Share on other sites More sharing options...
samifox Posted July 7, 2014 Author Share Posted July 7, 2014 Apply in mathArea 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? Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted July 8, 2014 Share Posted July 8, 2014 (edited) sorry i still dont understand...could it be simpler? hi hope this helps? pls advise if i get you wrong direction, thanx Edited July 8, 2014 by hanhphuc Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 8, 2014 Share Posted July 8, 2014 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. Quote Link to comment Share on other sites More sharing options...
samifox Posted July 8, 2014 Author Share Posted July 8, 2014 hi hope this helps? 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 Quote Link to comment Share on other sites More sharing options...
samifox Posted July 8, 2014 Author Share Posted July 8, 2014 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- ) Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted July 8, 2014 Share Posted July 8, 2014 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.