Jump to content

Recommended Posts

Posted

Hi all,

First post, but hopefully you will be kind to me, I have been lurking for a while, but this is the first time I have needed to post!

 

I am after learning Lisp routines, but havnt had time yet! I am after a very basic one I hope.

 

I need to find the bearing between two point clicks.

 

So basically, click once to set the origin and second click at the target location, then an output is given saying X,Y,Z of the first point, plus a bearing in Radians to the second click.

 

Is there a basic tut to produce something like this? or if anyone can show an example with comments that would be great.

Cheers

Brin

Posted
Hi all,

First post, but hopefully you will be kind to me, I have been lurking for a while, but this is the first time I have needed to post!

 

I am after learning Lisp routines, but havnt had time yet! I am after a very basic one I hope.

 

I need to find the bearing between two point clicks.

 

So basically, click once to set the origin and second click at the target location, then an output is given saying X,Y,Z of the first point, plus a bearing in Radians to the second click.

 

Is there a basic tut to produce something like this? or if anyone can show an example with comments that would be great.

Cheers

Brin

 

May we assume you want zero reference to be straight up or traditional "north" ? May we ask "why radians for bearing" ?

Posted

Hi Thanks for the reply, yes, North should be straight up, It needs to be radians because this data is to be used in another program which only accepts radians. If I can get the data as above, I can then run a macro in Programmers file editor to get it into the correct format. It is basicaly the eye point, plus a bearing, then the other program knows which way to "look"

 

Im assuming that the radians isnt a problem as I can get this info pretty quickly from CAD but Its a bit repetetive.

Posted

Hi Brin,

 

Not sure if this will get you started I hope it does. I wrote it to get horizontal distance and slope along with coordinates and bearing. It uses an alert function whereas you might want to get rid of that and just use the variables. It may still need some error trapping but as I'm a newbie too I'm not sure how to do all "that stuff".

 

(defun c:hzdplus (/ angtype oldir factp actp sdist hdist mang Nchar1 Nchar2 Echar1 Echar2 Zchar1 Zchar2)
 (setq angtype (getvar "AUNITS"))    ;;; Get current user Units
 (setq oldir (getvar "ANGDIR"))     ;;;; Get current user Direction
 (setq factp (getpoint "\nPick Point 1: ")      ;;; Store Point 1
actp  (getpoint factp "\nPick Point 2: ") ;;; Store Point 2
 )
 (setq sdist (rtos (distance factp actp)2 3))  ;;; Get slope Distance and store as string
 (setq coor1y (cadr factp)    ;;; Get Northing of Point 1
coor1x (car factp)    ;;; Get Easting of Point 1
coor1z (caddr factp)    ;;; Get Height of Point 1
 )
 (setq afact (list coor1x coor1y 0))    ;;; Store Easting and Northing with Height as 0 (for horizontal distance) of Point 1
 (setq coor2y (cadr actp)    ;;; Get Northing of Point 2
coor2x (car actp)    ;;; Get Easting of Point 2
coor2z (caddr actp)    ;;; Get Height of Point 2
 )
 (setq aact (list coor2x coor2y 0))    ;;; Store Easting and Northing with Height as 0 (for horizontal distance) of Point 2
 (setq Nchar1 (rtos coor1y 2 3)   ;;; Store North coordinate of Point 1 as String in decimal format
Echar1 (rtos coor1x 2 3)   ;;; Store East coordinate of Point 1 as String in decimal format
Zchar1 (rtos coor1z 2 3)   ;;; Store Height coordinate of Point 1 as String in decimal format
 )
 (setq Nchar2 (rtos coor2y 2 3)   ;;; Store North coordinate of Point 2 as String in decimal format
Echar2 (rtos coor2x 2 3)   ;;; Store East coordinate of Point 2 as String in decimal format
Zchar2 (rtos coor2z 2 3)   ;;; Store Height coordinate of Point 2 as String in decimal format
 )
 (if (< (strlen Nchar2)     ;;; <---- From here, Just error trapping for formatting in alert box, 
   (setq Nchar2 (strcat "\t" Nchar2)))   ;;; not totally correct but works for my coordinate system!
 (if (< (strlen Echar2) 
   (setq Echar2 (strcat "\t" Echar2)))
  (if (< (strlen Zchar2) 
   (setq Zchar2 (strcat "\t" Zchar2)))   ;;; <---- To here
 (setq mang (angle factp actp))   ;;; Get Angle in Radians
 (cond ((= angtype 0) (setq mang (angtos mang 0 4))) ;;; <--- From here
((= angtype 1) (setq mang (angtos mang 1 4)))
((= angtype 2) (setq mang (angtos mang 2 4)))
((= angtype 3) (setq mang (angtos mang 3 4)))
((= angtype 4) (setq mang (angtos mang 4 4))))  ;;; <---To here, Set angle to user Unit settings and convert to string
 (setq hdist (rtos (distance afact aact) 2 3))  ;;; Get horizontal distance from ht=0 point stored variable and convert to string
 (alert (strcat "\n\         RESULT\t"   ;;; Display the stuff
  "\n"
  "\n\Angle = " mang
  "\n"
  "\n\Slope Distance = " sdist
  "\n"
  "\n\Horizontal Distance = " hdist
  "\n\n"
  "\Point 1\t\tPoint 2"
  "\n"
  Nchar1
  "\t"
  Nchar2
  "\n"
  Echar1
  "\t"
  Echar2
  "\n"
  Zchar1
  "\t"
  Zchar2
 )
 )
 (princ)
)

 

All the best

Stu

Posted

Wow Thanks Stu!

Looks impressive ;o)

I will have to wait till I get to the CAD PC tomorrow to try it.

I take it, I appload this, then type "hzdplus" and perform the clicks. and I get a/the result in the screen echo?

I will need to step through each line before I have a clue what is going on!

Cheers

Posted
Wow Thanks Stu!

Looks impressive ;o)

I will have to wait till I get to the CAD PC tomorrow to try it.

I take it, I appload this, then type "hzdplus" and perform the clicks. and I get a/the result in the screen echo?

I will need to step through each line before I have a clue what is going on!

Cheers

 

 

Sorry Brin,

 

I edited the above lisp with "what the hell is going on" lines. Hope it makes sense now!

Posted

hehe, Thanks a lot!

It seems to do exactly what I was after. If I set my angle units in the drawing to Radians, it gives the output in Radians as well.

I will descreatly use this as is for now! then add another version if i manage to improve it at all.

 

Cheers

Posted
Sorry Brin,

 

I edited the above lisp with "what the hell is going on" lines. Hope it makes sense now!

 

Hi Scu,

Sorry, I don't know what is the bearing

but after I did run your code there are both distance

equal :

Slope distance = Horizontal distance

Is that right?

 

~'J'~

Posted
Hi Scu,

Sorry, I don't know what is the bearing

but after I did run your code there are both distance

equal :

Slope distance = Horizontal distance

Is that right?

 

~'J'~

 

Ah.. I think if both points are the same height e.g. both Z = 0 then horizontal = slope as there is no slope. I changed this program from my first simple version cause I used initget 64 to ignore Z values but then I couldn't get the Slope from the picked points.

 

If this isn't the case and they have different heights then I'm not sure why?!! Let me know if this is the case. Although you might have a better go at figuring it out as I'm still new at Lisp.

 

oh and Bearing.. Angle or azimuth people call it different things but this program suppose to work in relation to your angle direction (angdir = 0 or 1, = anti-clockwise or clockwise) and angle base in _units/direction setup. So if you set base angle to North it will be the angle from north in either clockwise or anti clockwise direction. I work in the southern hemisphere with North being up and clockwise.. not normal for CAD! I think I notice if using Land Desktop too.. it stuffs up all my programs I don't know why..database maybe?

 

Also my question is, why when you type angbase at command line (showing 90d on my computer), it is different to the menu.. format/ units/ direction/ angle base North = 270d? Are they different system variables?

Posted
Ah.. I think if both points are the same height e.g. both Z = 0 then horizontal = slope as there is no slope.

 

If this isn't the case and they have different heights then I'm not sure why?!! Let me know if this is the case.

Both point have the different heights...

Ok, as they said here, I need time to chew it

Will be back at tomorrow :)

 

~'J'~

Posted

Not sure why there is not more setvars to make sure all your angles and units are set correct rather than rely on user setting the UNITS you can use these change as required

 

 

(SETQ ANGBASEE (GETVAR "ANGBASE"))

(SETQ ANGDIRR (GETVAR "ANGDIR"))

(SETQ LUNITSS (GETVAR "LUNITS"))

(SETQ LUPRECC (GETVAR "LUPREC"))

(SETQ AUNITSS (GETVAR "AUNITS"))

(SETQ AUPRECC (GETVAR "AUPREC"))

 

(SETVAR "LUNITS" 2)

(SETVAR "ANGBASE" 0.0)

(SETVAR "ANGDIR" 0)

(SETVAR "LUPREC" 3)

(SETVAR "AUNITS" 0)

(SETVAR "AUPREC" 3)

 

 

reset at end

Posted
Not sure why there is not more setvars to make sure all your angles and units are set correct rather than rely on user setting the UNITS you can use these change as required

 

 

Good point BIGAL, maybe that'll be the problem. I have modified a copy of acad200#.doc to load all our drawings with the right settings for us. Obviously this program lacks a little integrity for other people!:oops: lol

 

So how's that aussie weather.. are you gonna send us (NZ) some fine weather?:wink:

Posted

Hi Chaps,

 

The slope distance works correctly when I run it, you have to snap to the point for the level to register. it needs to be a short distance or big change in level for the slope distance to be relevant. for instance 100mm level diffrence in 10m will give a slope distance of 10.0005

 

I have discovered an problem with the other program I use, It seems to only register strange angles! a whole circle is not 2 pi which would be 6.28... I need to figure out what the other program is asking for! it is called BS contact.

Posted

Just compare both results:

(setq hdist (rtos (distance afact aact) 2 3))  ; Get horizontal distance from ht=0 point stored variable and convert to string

and

(setq hdist (rtos (abs (- coor2x coor1x)) 2 3))

 

~'J'~

Posted

Thanks All, This looks like a simple lisp which is a good start for me to start learning!

 

right, I have got to the bottom of the other programs "quirk" It gives an xyz as expected, then also gives rotation in the form 0 -1 0 0 each figure gives a angle to rotate the view from, in each xyz plane, plus the -1 tells it to rotate clockwise or anticlockwise. A larger figure will give the correct firection as long as I set the -1 to be plus 1. This might make perfect sense to people people who work in 3D cad? but its all new to me... To many things to learn in one go! Cheers Alanjt. I will post in your thread as well...

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...