Want calculate z value from two points and get mid point with 3d value

Want calculate z value from two points and get mid point with 3d value

Anonymous
Not applicable
882 Views
5 Replies
Message 1 of 6

Want calculate z value from two points and get mid point with 3d value

Anonymous
Not applicable

Calculate z value from given two 3d point and and get mid of these point with z value

As show in jpg. It's show as side view

0 Likes
883 Views
5 Replies
Replies (5)
Message 2 of 6

cadffm
Consultant
Consultant
0 Likes
Message 3 of 6

ronjonp
Mentor
Mentor

Many ways to do this but as the benchmark shows, POLAR is the fastest 🙂

(setq p0 (getpoint)
      p1 (getpoint)
)
(benchmark '((polar p0 (angle p0 p1) (/ (distance p0 p1) 2.))
	     (mapcar '/ (mapcar '+ p0 p1) '(2. 2. 2.))
	     (mapcar '(lambda (a b) (/ (+ a b) 2.)) p0 p1)
	     (list
	      (/ (+ (car p0) (car p1)) 2.)
	      (/ (+ (cadr p0) (cadr p1)) 2.)
	      (/ (+ (caddr p0) (caddr p1)) 2.)
	     )
	    )
)
;;;Benchmarking .................Elapsed milliseconds / relative speed for 16384 iteration(s):
;;;
;;;    (POLAR P0 (ANGLE P0 P1) (/ (DISTANCE...).....1719 / 2.15 <fastest>
;;;    (LIST (/ (+ (CAR P0) (CAR P1)) 2.0) ...).....2469 / 1.50
;;;    (MAPCAR (QUOTE (LAMBDA (A B) (/ (+ A...).....3125 / 1.18
;;;    (MAPCAR (QUOTE /) (MAPCAR (QUOTE +) ...).....3703 / 1.00 <slowest>
0 Likes
Message 4 of 6

MunteanStefan
Contributor
Contributor


@ronjonp wrote:

Many ways to do this but as the benchmark shows, POLAR is the fastest 🙂



Careful with polar function, it works only in 2D.
Also, the anlge function will project the 3D points into xOy plan
_$ (setq p0 '(0.0 0.0 100.0) p1 '(50.0 80.0 150.0))
_$ (polar p0 (angle p0 p1) (/ (distance p0 p1) 2.0))  ->  (28.2942 45.2707 100.0)
_$ (polar p1 (angle p1 p0) (/ (distance p1 p0) 2.0))  ->  (21.7058 34.7293 150.0)
0 Likes
Message 5 of 6

ronjonp
Mentor
Mentor

Oops! You are totally correct. Learned something new today 🙂

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@ronjonp wrote:

Many ways to do this but as the benchmark shows, POLAR is the fastest 🙂


 

[Written while others were posting with the same thought, but hey -- color and boldface and italics are always impactful....]

 

HOWEVER, (angle) operates only in 2D.  [Maybe that's why it's faster!]  The AutoLisp Reference entry for (angle) says:

  If 3D points are supplied, they are projected onto the current construction plane.

So:

  (setq p0 '(0 0 0) p1 '(2 2 2))

Halfway between them should be '(1 1 1), but:

  (polar p0 (angle p0 p1) (/ (distance p0 p1) 2.))

returns:
  (1.22474 1.22474 0.0)

Whereas:

  (mapcar '/ (mapcar '+ p0 p1) '(2 2 2))

returns:
  (1.0 1.0 1.0)

Kent Cooper, AIA
0 Likes