### Author Topic: passing vectors to a function  (Read 10442 times)

0 Members and 1 Guest are viewing this topic.

#### Shay Gaghe

• Newt
• Posts: 89
##### Re: passing vectors to a function
« Reply #15 on: July 10, 2014, 12:46:02 PM »
It's not perpendicular

thanks

i update the shape , what math is to be applied here in order to get answer 0?

#### Lee Mac

• Seagull
• Posts: 12913
• London, England
##### Re: passing vectors to a function
« Reply #16 on: July 10, 2014, 01:49:16 PM »
Firstly, note that you would need to supply the function with the vectors (-1.1 5.6) & (5.6 1.2), since you are looking for the vectors emanating from the point (8.4 -2.3):
Code - Auto/Visual Lisp: [Select]
1. _\$ (mapcar '- '(7.3 3.3) '(8.4 -2.3))
2. (-1.1 5.6)
3. _\$ (mapcar '- '(14.0 -1.1) '(8.4 -2.3))
4. (5.6 1.2)

However, these vectors are still not perpendicular (89.0183 degrees apart):
Code - Auto/Visual Lisp: [Select]
1. _\$ (rtd (acos (/ (vxv '(-1.1 5.6) '(5.6 1.2)) (|v| '(-1.1 5.6)) (|v| '(5.6 1.2)))))
2. 89.0183

#### Shay Gaghe

• Newt
• Posts: 89
##### Re: passing vectors to a function
« Reply #17 on: July 10, 2014, 02:19:35 PM »
Firstly, note that you would need to supply the function with the vectors (-1.1 5.6) & (5.6 1.2), since you are looking for the vectors emanating from the point (8.4 -2.3):
Code - Auto/Visual Lisp: [Select]
1. _\$ (mapcar '- '(7.3 3.3) '(8.4 -2.3))
2. (-1.1 5.6)
3. _\$ (mapcar '- '(14.0 -1.1) '(8.4 -2.3))
4. (5.6 1.2)

However, these vectors are still not perpendicular (89.0183 degrees apart):
Code - Auto/Visual Lisp: [Select]
1. _\$ (rtd (acos (/ (vxv '(-1.1 5.6) '(5.6 1.2)) (|v| '(-1.1 5.6)) (|v| '(5.6 1.2)))))
2. 89.0183
Where I can find all those math functions like vxv , v etc?

#### LE3

• Guest
##### Re: passing vectors to a function
« Reply #18 on: July 10, 2014, 02:26:55 PM »
You need to take a trip/visit to Lee's site:
http://www.lee-mac.com/index.html

And spend some time reading all the GREAT STUFF, he have in there for many to simple use OOB or to learn (<- I recommend)... AFAIK some of those function names are Lee's... HTH

#### Lee Mac

• Seagull
• Posts: 12913
• London, England
##### Re: passing vectors to a function
« Reply #19 on: July 10, 2014, 02:28:01 PM »
Where I can find all those math functions like vxv , v etc?

#### Lee Mac

• Seagull
• Posts: 12913
• London, England
##### Re: passing vectors to a function
« Reply #20 on: July 10, 2014, 02:28:28 PM »
You need to take a trip/visit to Lee's site:
http://www.lee-mac.com/index.html

And spend some time reading all the GREAT STUFF, he have in there for many to simple use OOB or to learn (<- I recommend)... AFAIK some of those function names are Lee's... HTH

Many thanks Luis - that's very kind of you

#### Shay Gaghe

• Newt
• Posts: 89
##### Re: passing vectors to a function
« Reply #21 on: July 10, 2014, 02:38:44 PM »
Where I can find all those math functions like vxv , v etc?

Yes you did, I find it now under the scary  word "metrix" so no wonder how I've missed it.
Is there any mathematical explination about those functions?

#### Lee Mac

• Seagull
• Posts: 12913
• London, England
##### Re: passing vectors to a function
« Reply #22 on: July 10, 2014, 02:43:44 PM »
Is there any mathematical explination about those functions?

Certainly, simply type the function names (e.g. 'Vector Dot Product' or 'Matrix Determinant') into Wikipedia.

#### Tharwat

• Swamp Rat
• Posts: 710
• Hypersensitive
##### Re: passing vectors to a function
« Reply #23 on: July 10, 2014, 05:07:39 PM »
Lee . Won't the following would be equivalent at anyway ?

Code - Auto/Visual Lisp: [Select]
1. (defun Perpendicular-p (p1 org p2 / v)
2.   ;;    Tharwat 11.July.2014    ;;
3.   (or (equal (setq v (abs (- (angle p1 org) (angle p2 org))))
4.              4.71239
5.              1e-4
6.       )
7.       (equal v 1.5708 1e-4)
8.   )
9. )
10.

#### Lee Mac

• Seagull
• Posts: 12913
• London, England
##### Re: passing vectors to a function
« Reply #24 on: July 10, 2014, 05:17:40 PM »
Lee . Won't the following would be equivalent at anyway ?

Yes, however the use of the angle function will mean that 3D vectors will be dependent on the UCS.

#### Tharwat

• Swamp Rat
• Posts: 710
• Hypersensitive
##### Re: passing vectors to a function
« Reply #25 on: July 10, 2014, 06:01:26 PM »
Lee . Won't the following would be equivalent at anyway ?

Yes, however the use of the angle function will mean that 3D vectors will be dependent on the UCS.

Excellent - very precise

#### Shay Gaghe

• Newt
• Posts: 89
##### Re: passing vectors to a function
« Reply #26 on: July 11, 2014, 01:06:51 AM »
hi

this code apply Lee's code on a selected entity ,

Code: [Select]
`(defun entsel-pre-p (/ ent vertex vertexList u v vos)  (if (setq ent (car (entsel "\nSelect an object")))    (if (setq ent (entget ent))      (progn (foreach vertex ent   (if (= (car vertex) 10)     (setq vertexList (cons (cdr vertex) vertexList))   ) ) (setq   v (car vertexList)   u (car (reverse vertexList)) ) (setq vos (apply '+ (mapcar '* u v))) (equal 0.0 vos 1e-8)      )    )  ))`
if the selected poly origin is on 0,0,0 the function returns T , but if i move the poly and execute the code again it returns nil.
what i missing here?

Shay

#### Kerry

• Mesozoic relic
• Seagull
• Posts: 11654
• class keyThumper<T>:ILazy<T>
##### Re: passing vectors to a function
« Reply #27 on: July 11, 2014, 01:10:18 AM »
Shay Gaghe,

If you're travelling in space and you are located at 10, 25,13 and you want to travel to Uranus which is at 12,21,15 ; what vector will Sulu need to
use to navigate to your destination?

(distances in parsecs).
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

#### Kerry

• Mesozoic relic
• Seagull
• Posts: 11654
• class keyThumper<T>:ILazy<T>
##### Re: passing vectors to a function
« Reply #28 on: July 11, 2014, 01:17:42 AM »
Regarding the piccy you posted,
What is the vector for each of the arms in the left grid .. and in the right grid.?

ie:
What is it's Length, Delta X and Delta Y dimensions ?
« Last Edit: July 11, 2014, 01:23:30 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

#### Shay Gaghe

• Newt
• Posts: 89
##### Re: passing vectors to a function
« Reply #29 on: July 11, 2014, 01:27:36 AM »
Regarding the piccy you posted,
What is the vector for each of the arms in the left grid .. and in the right grid.?

ie:
What is it's Length, Delta X and Delta Y dimensions ?

i must know the location of Sulu
Regarding the piccy you posted,
What is the vector for each of the arms in the left grid .. and in the right grid.?

ie:
What is it's Length, Delta X and Delta Y dimensions ?