Autolisp place point at designated location

Autolisp place point at designated location

Anonymous
Not applicable
1,065 Views
2 Replies
Message 1 of 3

Autolisp place point at designated location

Anonymous
Not applicable

Hello all,

I have a 18x12 linear grid with spot elevations at every intersection. I need to interpolate contour points on the given segments between spots. So the math its self is simple:

 

Let's say we have two spot elevations A & B. A = 69.4 and B = 71.4. The distance between A & B = 50 feet. We want to know where the 70 foot contour would fall between spot elevations A & B. First obtain the total elevation difference. This is done by subtracting A from B. 71.4 minus 69.4 = 2. Next we want the difference in elevation between our 70 contour interval and the nearest spot elevation which in this case is A or 69.4. That works out to be 0.6. Now we need to calculate the distance (let's call this "d") we need to go from spot elevation A to our 70 foot contour. That takes the form of: d=0.6*50/2 = 0.6*25 = 15 or the distance, in decimal feet, to our 70 foot contour. From there we would place a point 15 units from A and that is where the 70 foot contour point is on the line segment.

 

Due to it being a grid of 432ish segments, some having no points and others having up to 5, it is a very long a tedious process to do every segment. I have found different routines that do the job relatively but there is a part of them that does not work with what is needed(wrong contour interval, needs 3d points instead of 2d like I have, etc.). So I have been working on learning lisp while trying to create a routine to address my problem. I have made what logic I can from what I have gathered but I do not know how to get the routine to work. Below is what I came up with and below that is where I worked through the logic to verify it when I could.

a=69.4
b=71.4
dis=50
contour=70
71.4-69.4=2
70-69.4=0.6
d=0.6*50/2
d=0.6*25
d=15

(defun c:interp1 (/a b e f cont d)
	(setvar "PDMODE" 34)
  	(setvar "PDSIZE" 5)

  	(setq e (getpoint "\nPick Point 1: "))
	(setq a (getreal "\nSpecify First Height: "))
	(setq f (getpoint "\nPick Point 2: "))
	(setq b (getreal "\nSpecify Second Height: "))
	(setq cont (getreal "\nSpecify Contour Needed: "))

	(setq d (*(/ (distance e f) (- b a)) (- cont a)))
	(setq g (polar (a) 0 d)); should return the UCS point needed
	(entmake ((0 "POINT") (10 g)))
  (princ))


(defun c:interp2 (/a b e f cont d)
	(setvar "PDMODE" 34)
  	(setvar "PDSIZE" 5)

  	(setq e = 521962 44395 (getpoint "\nPick Point 1: "))
	(setq a = 69.4 (getreal "\nSpecify First Height: "))
	(setq f = 521912 44395 (getpoint "\nPick Point 2: "))
	(setq b = 71.4 (getreal "\nSpecify Second Height: "))
	(setq cont = 70(getreal "\nSpecify Contour Needed: "))

	(setq d (*(/ (distance 521962 44395 521912 44395) (- 71.4 69.4)) (- 70 69.4)))
  	(setq d (*(/ (50) (2)) (0.6)))
  	(setq d (*(25) (0.6)))
  	(setq d (15)
	      
	(setq g (polar (69.4) 0 15)); should return the UCS point needed
	(entmake ((0 "POINT") (10 521947 44395)));"521947 44395" is the correct answer, not sure if "g" returns this though...
  (princ))

It would be greatly appreciated if I could have some help getting the routine to work. I understand that there is going to be a better & cleaner way of doing it, and by all means anyone can share and I may use it. But I would also like the routine I wrote to work and an explanation on what was added/modified so I can learn from it rather than just getting a solution and not understanding it.

 

 

Thank you for your time,

Austin Casteel

0 Likes
Accepted solutions (1)
1,066 Views
2 Replies
Replies (2)
Message 2 of 3

ВeekeeCZ
Consultant
Consultant
Accepted solution

Jast a syntax fix, didn't look into an algorithm.

 

(defun c:interp1 (/ a b e f cont d) ; has to be space behing /
  (setvar "PDMODE" 34)
  (setvar "PDSIZE" 5)
  
  (setq e (getpoint "\nPick Point 1: "))
  (setq a (getreal "\nSpecify First Height: "))
  (setq f (getpoint "\nPick Point 2: "))
  (setq b (getreal "\nSpecify Second Height: "))
  (setq cont (getreal "\nSpecify Contour Needed: "))
  
  (setq d (* (/ (distance e f) (- b a)) (- cont a)))  ; be careful of div 0. You should not allow that.
  (setq g (polar e 0 d)); should return the UCS point needed ; first has to be some point!!
  (entmake (list '(0 . "POINT") (cons 10 g)))  ; ' just for constanst, cons or list for variables that have to be avaluated
  (princ))

 

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you for the help, I knew it would be something simple that I overlooked or did not know. But nevertheless it worked wonderfully, as far as the horizontal segment. I flew through the horizontal segments and started on the vertical and realized an issue in the code.

 

It calculates everything properly except puts the point the correct distance but on the x-axis instead of y. I duplicated the code, since the HORZ works, and started to work on modifications to get the VERT to work. My initial thought process was to add an angle to the polar but adding 90° actually moved it too far, placed it at 116°. So I took 16° away and made it 74° in hopes of shifting it over enough. Instead of placing it correctly it placed the point at 280° or -80°. So now I am at a loss....

 

Edit: Turns out degrees and radians are two different things, who knew... Smiley LOL