Saturday, November 21, 2009
Home   |   Search   |   About AUGI   |   My AUGI   |   Join Now

Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP
 Welcome, Guest. 

Login

Join Now FAQ Members List Calendar Search Today's Posts Mark Forums Read

AutoLISP AutoLISP or Visual LISP, learn both here!

Reply
 
Thread Tools Display Modes
Old 2004-07-27, 02:18 AM   #1
david.larkin
Member
 
Join Date: 2001-11
Posts: 5
david.larkin is starting their journey
Question Distance between 3d Planes

Does anyone have a routine that measures the shortest distance between 3D planes ?

There doesn't seems to be any AutoCAD 2002 command for it.
david.larkin is offline   Reply With Quote
Old 2004-07-27, 04:00 AM   #2
sinc
AUGI Addict
 
sinc's Avatar
 
Join Date: 2004-02
Location: Colorado
Posts: 1,531
sinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the stars
Default

If you set either plane to be the xy-plane of a UCS, then the z-coordinate of any point on the other plane is the distance between the planes...

It isn't really the "shortest" distance... It's the "distance". Your question is only valid if the planes are parallel. Otherwise, they intersect, and the shortest distance between them is 0.

I don't know if this helps you or not. What exactly are you trying to do?
__________________
-- Sinc
Civil-3D/Map 2009
http://www.ejsurveying.com
http://www.quuxsoft.com
(Sincpac-C3D)

Last edited by sinc : 2004-07-27 at 04:05 AM.
sinc is offline   Reply With Quote
Old 2004-07-27, 01:24 PM   #3
peter
Vice President / Director
 
peter's Avatar
 
Join Date: 2000-09
Location: Kenosha Wisconsin
Posts: 375
peter is shooting for the starspeter is shooting for the starspeter is shooting for the starspeter is shooting for the starspeter is shooting for the starspeter is shooting for the starspeter is shooting for the starspeter is shooting for the starspeter is shooting for the starspeter is shooting for the starspeter is shooting for the stars
Default RE: Distance between 3d Planes

I assume that you are not considering infinite planes but finite plane surfaces like 3dfaces.

Although I don't have the solution as code, I could make some suggestions as to how to solve this puzzle.

First each surface has a normal that is perpendicular to its face.
Well you have to figure out what that is.
Check your matrix mathmatics for formulas to figure those out.

I would then create a series of conditionals that would use the normal as a vector and place them at each vertice of each 3dface and then figure out how to find the distance to the intersection of that vector to the other surface. Again I would use matrix math to do that.

Whichever is shorter is the closest distance.

Peter Jamtgaard
peter is offline   Reply With Quote
Old 2004-07-27, 03:16 PM   #4
sinc
AUGI Addict
 
sinc's Avatar
 
Join Date: 2004-02
Location: Colorado
Posts: 1,531
sinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the stars
Default RE: Distance between 3d Planes

AutoCAD has routines that return the normal of an object and return the intersection of a plane and a line (the later is in the cal routine), but that will only work if one of the 3D faces is oriented so that the normal even hits the other 3D face... The shortest distance might be a non-normal vector from a corner of one 3D face to a corner of the other, or corner to a point on the other 3D face, or even something like a point on the edge of one 3D face to a point on the edge of the other 3D face.

I'm not sure what the easiest way of approaching it would be.
__________________
-- Sinc
Civil-3D/Map 2009
http://www.ejsurveying.com
http://www.quuxsoft.com
(Sincpac-C3D)

Last edited by sinc : 2004-07-27 at 03:49 PM.
sinc is offline   Reply With Quote
Old 2004-07-27, 03:48 PM   #5
sinc
AUGI Addict
 
sinc's Avatar
 
Join Date: 2004-02
Location: Colorado
Posts: 1,531
sinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the stars
Default RE: Distance between 3d Planes

I'm thinking maybe of drawing a polyline around the edge of each 3D face. Then from each vertex of the first 3D face, find the distance to the closest point on the polyline around the second 3D face using vlax-curve-getClosestPointTo. Repeat, using the vertices of the second 3D face and the polyline around the first 3D face. The shortest distance you find will be the shortest distance between in all cases except when the shortest distance is from the corner of one 3D face to a point on the surface of the other, or the case when the closest distance is from a point on one edge to a point on the other edge...

Now, how best to detect those cases?
__________________
-- Sinc
Civil-3D/Map 2009
http://www.ejsurveying.com
http://www.quuxsoft.com
(Sincpac-C3D)
sinc is offline   Reply With Quote
Old 2004-07-27, 08:40 PM   #6
sinc
AUGI Addict
 
sinc's Avatar
 
Join Date: 2004-02
Location: Colorado
Posts: 1,531
sinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the stars
Default RE: Distance between 3d Planes

How about the following pseudo-code:

Code:
<draw polylines (p1, p2) around each face (f1, f2)>
<get shortest distance from each vertex of p1 to p2 using vlax-curve-getClosestPointTo>
<get shortest distance from midpoint of each segment of p1 to p2 similarly>
<repeat last two steps for p2 to p1>

<if>
  <shortest distance found above is from a corner, you found it>
<else if>
  <shortest distance found above is from a midpoint, then:>
<if> <two and only two opposite sides have shorter distances from the midpoint than from either adjacent vertex, then shortest distance is from edge to edge; in this case the shortest distance is between [the point you found on p2 that's closest to p1] and [the point you found on p1 that's closest to p2])> <else> <shortest distance vector is normal to the other plane and hits somewhere on its surface; figure it using cal to locate the intersection of a line and a plane> <endif>
<endif>
__________________
-- Sinc
Civil-3D/Map 2009
http://www.ejsurveying.com
http://www.quuxsoft.com
(Sincpac-C3D)
sinc is offline   Reply With Quote
Old 2004-07-28, 06:15 AM   #7
david.larkin
Member
 
Join Date: 2001-11
Posts: 5
david.larkin is starting their journey
Cool RE: Distance between 3d Planes

Peter is correct that I am working with finite plane surfaces using solids in most cases.

His suggestion is probably the best way of solving this puzzle.

What I have been trying to do is to find the minimum clearances between existing and new structures. Finding out where it clashes is easy. Finding out where the minimum clearance are is more tricky and very time consuming.

Looks like this is a big job to create this routine. Have to give this a miss as I have a short time frame to complete this 3D project I am working on.

Thanks for the hints guys.
david.larkin is offline   Reply With Quote
Old 2004-07-28, 02:38 PM   #8
sinc
AUGI Addict
 
sinc's Avatar
 
Join Date: 2004-02
Location: Colorado
Posts: 1,531
sinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the stars
Default

Can't that be done with simple elevation comparisons?
__________________
-- Sinc
Civil-3D/Map 2009
http://www.ejsurveying.com
http://www.quuxsoft.com
(Sincpac-C3D)
sinc is offline   Reply With Quote
Old 2004-07-28, 09:09 PM   #9
stig.madsen
100 Club
 
Join Date: 2000-12
Posts: 126
stig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightly
Default RE: Distance between 3d Planes

Quote:
Originally Posted by david.larkin
Looks like this is a big job to create this routine.
Could be. Then again, might be easier than it sounds. All depends on circumstances.

Simply finding the distance between a point and a plane is not a problem. If you're working with finite, planar surfaces then it would suffice to check the vertices because - if the surface planes are not parallel - one of the vertices will always describe the shortest distance between the surfaces. Of course, if it's required that projected vertices of one surface are located within the other surface - and project edges onto the surface - then it might be a little more work.

As Richard points out, it's already part of the CAL program. But here's a purely mathematical approach to find the distance between a point and a plane. If you're working with planar 3Dfaces then simply extract all 3 or 4 vertices and get the minimum distance from those of all points to the plane of the other surface (if 4 vertices then have in mind that a 3DFace can describe two planes). The function to use or modify is getDistToPlane. The others are utility functions.

Code:
(defun getDistToPlane (/ p0 p1 p2 p3 dist norm)
  ;; getting user input. This could easily be changed in order
  ;; to receive a plane and a point, e.g. a vertice to check
  (cond ((and (setq p2 (getpoint "\nOrigin: "))
              (setq p1 (getpoint p2 "\nFirst axis direction: "))
              (setq p3 (getpoint p2 "\nSecond axis direction: "))
              (setq p0 (getpoint "\nPick point: "))
         )
         ;; transform all points to WCS
         (mapcar (function (lambda (p) (set p (trans (eval p) 1 0))))
                 '(p1 p2 p3 p0)
         )
         ;; find normal vector to plane p1-p2-p3
         ;; and distance from point p0 to plane
         (setq norm (V3Normalize (V3Cross (V3Sub p2 p1) (V3Sub p3 p1)))
               dist (V3Dot norm (V3Sub p0 p1))
         )
         (abs dist)
        )
  )
)

;;; Return the cross product, vec1 cross vec2
(defun V3Cross (vec1 vec2)
  (list (- (* (cadr vec1) (caddr vec2)) (* (caddr vec1) (cadr vec2)))
        (- (* (caddr vec1) (car vec2)) (* (car vec1) (caddr vec2)))
        (- (* (car vec1) (cadr vec2)) (* (cadr vec1) (car vec2))))
)

;;; Return the dot product of vectors vec1 and vec2
(defun V3Dot (v1 v2)
  (apply '+ (mapcar '* v1 v2))
)

;;; Return vector difference vec1-vec2 (notice sequence)
(defun V3Sub (vec1 vec2)
  (mapcar '- vec1 vec2)
)

;;; Returns squared length of input vector
(defun V3SquaredLength (vec / expt2)
  (defun expt2 (a)
    (* a a)
  )
  (apply '+ (mapcar 'expt2 vec))
)

;;; Returns length of input vector 
(defun V3Length (vec)
  (sqrt (V3SquaredLength vec))
)

;;; Normalizes the input vector and returns it
(defun V3Normalize (vec / len)
  (if (/= (setq len (V3Length vec)) 0.0)
    (mapcar (function (lambda (a) (/ a len))) vec)
    vec
  )
)
stig.madsen is offline   Reply With Quote
Old 2004-07-28, 09:31 PM   #10
sinc
AUGI Addict
 
sinc's Avatar
 
Join Date: 2004-02
Location: Colorado
Posts: 1,531
sinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the starssinc is shooting for the stars
Default RE: Distance between 3d Planes

Quote:
Originally Posted by stig.madsen
If you're working with finite, planar surfaces then it would suffice to check the vertices because - if the surface planes are not parallel - one of the vertices will always describe the shortest distance between the surfaces.
Well, no. It is very possible that the shortest distance between the two 3D faces is along a vector that hits somewhere on the edge of either one or both planes, and the faces don't have to be parallel. It might help if you pull out a couple of business cards (or wait - aren't you on vacation, Stig? - make that "playing cards" ) or similar item and hold them next too each other in various ways; I'm sure you'll run into several such orientations quite quickly. And if a corner of one is pointed toward the other, the shortest-distance-vector may even hit in the somewhere on the interior of the other plane, nowhere near either an edge or a vertex (but in this case the problem degenerates into the simple distance-to-a-plane problem).

That's why I have all the "check midpoints" rigamarole in the pseudocode above.

All this may be moot, though; if the problem is really to find the CLEARANCE between objects, that's a different problem that might have a simpler solution...
__________________
-- Sinc
Civil-3D/Map 2009
http://www.ejsurveying.com
http://www.quuxsoft.com
(Sincpac-C3D)

Last edited by sinc : 2004-07-28 at 09:39 PM.
sinc is offline   Reply With Quote
Reply


Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Point at some distance between 2 points - best practice? KevinBarnett VBA 0 2004-07-09 07:47 AM
Locking Circles and reference planes Carl Revit Architecture - General 6 2004-06-16 04:20 PM
Psycho reference planes? Les Therrien Revit Architecture - General 10 2004-03-15 05:01 PM
Reference Planes and Views on Sheets JamesVan Revit Architecture - General 5 2003-08-08 03:38 PM
work planes cant be ref planes?? Martin P Revit Architecture - General 2 2003-06-10 01:25 PM


All times are GMT +1. The time now is 12:47 PM.