Discussion Groups

All Discussion Groups » Visual LISP, AutoLISP and General Customization Issues

Thread: Dividing distance of 2 variables


Permlink Replies: 12 - Last Post: Feb 3, 2009 3:06 AM Last Post By: Bill Gilliss
structure_fire3

Posts: 24
Registered: 01/22/09
Dividing distance of 2 variables
Posted: Feb 2, 2009 9:05 PM
  Click to reply to this thread Reply
I am trying to take the distance between 2 points and divide that by another variable. Everything works, but my definition of (dist1) doesnt work. Does anyone know how I can do this?



(setq p2 (getpoint "\nPick starting point:")
p3 (getpoint "\nPick Ending point:")
p4 (getreal "\nEnter Spacing:"))
dist1 ((distance p2 p3)/ p4)
);end setq
DEVITG

Posts: 1,283
Registered: 03/14/04
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:25 PM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply
Lisp allow the operator before the arguments



(setq p2 (getpoint "\nPick starting point:")

p3 (getpoint "\nPick Ending point:")

p4 (getreal "\nEnter Spacing:"))

dist1 (/ (distance p2 p3) p4); The operator / for divisio , shall be before any argument or operand

);end setq



see it



from



http://ronleigh.info/autolisp/afude01.htm



Function
Definitions



1
- Mathematics


+ ..... Adds


(+ 2 3) returns 5


(+ 4 5.6 -2) returns 7.6


After (setq a 20 b 9)


(+ a b) returns 29




- ..... Subtracts


(- 9 7) returns 2


(- 8 4 0.5) returns 3.5


After (setq a 20 b 9)


(- a b) returns 11


(- b a) returns -11


(- a) returns -20. When only one argument is supplied, its value
is subtracted from 0, switching the sign of any number.




* ..... Multiplies


(* 6 7) returns 42


(* 2 -3 1.5) returns -9.0


After (setq a 3 b 4.5)


(* a b) returns 13.5


(* a a) returns 9




/ ..... Divides
(/ 12 6) returns 2


(/ 11 6) returns 1 (Division using only integers ignores any
remainder. Beware of "integer division.")


(/ 11 6.0) returns 1.833333


(/ 12 3 2) returns 2


(/ 12 -2.0) returns -6.0
Some Buddy
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:27 PM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply


Hi,

 

AutoLISP uses the Polish notation als known as the
prefix notation, where the operators are placed at the left of their
operands.

So in this case, your code becomes (/ (distance p2
p3) p4).

 

Regards


<structure_fire3> a écrit dans le message de news: 6116548@discussion.autodesk.com...
I
am trying to take the distance between 2 points and divide that by another
variable. Everything works, but my definition of (dist1) doesnt work. Does
anyone know how I can do this? (setq p2 (getpoint "\nPick starting point:") p3
(getpoint "\nPick Ending point:") p4 (getreal "\nEnter Spacing:")) dist1
((distance p2 p3)/ p4) );end setq

structure_fire3

Posts: 24
Registered: 01/22/09
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:34 PM   in response to: Some Buddy in response to: Some Buddy
  Click to reply to this thread Reply
thanks I figured I had the divide symbol in the wrong place.
Now I'm having an issue with my IF command after, could you take a look and see if you can spot why.



(if (list (car p3) = (car p2))
(command "-array" PAUSE "R" dist "1" p4)
(command "-array" PAUSE "R" "1" dist p4)
);close IF


I'm trying to say IF the car of p2 and p3 are the same then run the 1st command, if not run the 2nd.
EC-CAD

Posts: 5,923
Registered: 12/12/03
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:37 PM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply
Try this one:
(if (eq (car p3)(car p2))
Bob
Some Buddy
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:42 PM   in response to: EC-CAD in response to: EC-CAD
  Click to reply to this thread Reply


Hi Bob,

 

Just curious, does it really make a difference
using eq instead of =, since (car ...) of a
point list is always a real ?

 


<EC-CAD> a écrit dans le message de news: 6116593@discussion.autodesk.com...
Try
this one: (if (eq (car p3)(car p2)) Bob

EC-CAD

Posts: 5,923
Registered: 12/12/03
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:44 PM   in response to: Some Buddy in response to: Some Buddy
  Click to reply to this thread Reply
No, in this case, doesn't matter.
For 'some' equivalent checks, you may need
the (eq .. instead. Try (if (= ent1 ent2)
for example.
He may need a 'fuzz' factor as well, for those 'real's.
:)
Bob

Edited by: EC-CAD on Feb 2, 2009 9:48 PM
Some Buddy
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:50 PM   in response to: EC-CAD in response to: EC-CAD
  Click to reply to this thread Reply


Yes, I know about these, in fact the eq function determines whether two expressions are bound to the same object (by setq, for example), but in this case I thought that it
was about comparing arguments for numerical equality, so this is why I
was asking, thinking that maybe there is some tip that I don't know
about.

 

Regards


<EC-CAD> a écrit dans le message de news: 6116599@discussion.autodesk.com...
No,
in this case, doesn't matter. For 'some' equivalent checks, you may need the
(eq .. instead. Try (if (= ent1 ent2) for example.
Bob

Jim Claypool
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:38 PM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply


(if (= (car pt3) (car pt2)) (command "-array" PAUSE "R" dist "1" p4) (command
"-array" PAUSE "R" "1" dist p4) );


<structure_fire3> wrote in message news:6116591@discussion.autodesk.com...
thanks
I figured I had the divide symbol in the wrong place. Now I'm having an issue
with my IF command after, could you take a look and see if you can spot why.
(if (list (car p3) = (car p2)) (command "-array" PAUSE "R" dist "1" p4)
(command "-array" PAUSE "R" "1" dist p4) );close IF I'm trying to say IF the
car of p2 and p3 are the same then run the 1st command, if not run the
2nd.

Some Buddy
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:39 PM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply


It is the same issue and some other
errors:

 

(if (=  (car p3) (car
p2))

   (command "-array" PAUSE "R" dist "1"
p4)

   (command "-array" PAUSE "R" "1" dist
p4)

)

 


<structure_fire3> a écrit dans le message de news: 6116591@discussion.autodesk.com...
thanks
I figured I had the divide symbol in the wrong place. Now I'm having an issue
with my IF command after, could you take a look and see if you can spot why.
(if (list (car p3) = (car p2)) (command "-array" PAUSE "R" dist "1" p4)
(command "-array" PAUSE "R" "1" dist p4) );close IF I'm trying to say IF the
car of p2 and p3 are the same then run the 1st command, if not run the
2nd.

structure_fire3

Posts: 24
Registered: 01/22/09
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:41 PM   in response to: Some Buddy in response to: Some Buddy
  Click to reply to this thread Reply
Thanks! Once again, some things in the wrong places. Need more coffee I guess.
Bill Gilliss
Re: Dividing distance of 2 variables
Posted: Feb 3, 2009 3:06 AM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply
structure_fire3 wrote:
Thanks! Once again, some things in the wrong places. Need more coffee
I guess.

Or less... 8-)
DEVITG

Posts: 1,283
Registered: 03/14/04
Re: Dividing distance of 2 variables
Posted: Feb 2, 2009 9:41 PM   in response to: structure_fire3 in response to: structure_fire3
  Click to reply to this thread Reply
Logical operators ALSO shall be before the arguments.