TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Adesu on January 15, 2008, 03:59:51 AM

Title: How to know area
Post by: Adesu on January 15, 2008, 03:59:51 AM
Hi,
my friend ask to me to know area of object with have elevation, look at attach file.
Title: Re: How to know area
Post by: Joe Burke on January 15, 2008, 07:46:21 AM
Hi Ade,

Given a 3D pline, the area command will only work when all the Z values of the vertex points are the same. So to get the "apparent" area of the 3D pline in your example you would flatten a copy and get the area of the copy. Then delete the copy.

If this does not have to be done within LISP I think the ExpressTools flatten command could be used.
Title: Re: How to know area
Post by: VovKa on January 15, 2008, 11:48:42 AM
or you can retrieve the coordinates, strip off the z's, and calculate the area analytically
Title: Re: How to know area
Post by: Guest on January 15, 2008, 11:54:18 AM
Can you use the BOUNDARY command on a 3D pline?  If so, you could do that using lsp, then retrieve the area of the newly created pline "boundary", then delete it afterwards.
Title: Re: How to know area
Post by: VovKa on January 15, 2008, 01:52:32 PM
Code: [Select]
(defun Get3dVx (EntName)
  ((lambda (e)
     (if (= (cdr (assoc 0 e)) "VERTEX")
       (cons (cdr (assoc 10 e)) (Get3dVx (entnext EntName)))
     )
   )
    (entget (entnext EntName))
  )
)
(defun GetArea (CoordsList)
  (abs
    (/ (apply '+
      (mapcar (function
(lambda (p1 p2) (* (+ (car p1) (car p2)) (- (cadr p1) (cadr p2))))
      )
      CoordsList
      (cons (last CoordsList) CoordsList)
      )
       )
       2.0
    )
  )
)
;(GetArea (Get3dVx (car (entsel "Select 3D polyline:"))))
Title: Re: How to know area
Post by: Fatty on January 15, 2008, 03:13:38 PM
Hi VovKa
How about to check IsPlanar property before?
Regards,
 :-)

~'J'~
Title: Re: How to know area
Post by: VovKa on January 15, 2008, 03:24:28 PM
Hi VovKa
How about to check IsPlanar property before?
Regards,
 :-)

~'J'~

feel free to modify, Fatty ;)
Title: Re: How to know area
Post by: Adesu on January 15, 2008, 06:39:51 PM
Woooow.........it's great,thanks.

Code: [Select]
(defun Get3dVx (EntName)
  ((lambda (e)
     (if (= (cdr (assoc 0 e)) "VERTEX")
       (cons (cdr (assoc 10 e)) (Get3dVx (entnext EntName)))
     )
   )
    (entget (entnext EntName))
  )
)
(defun GetArea (CoordsList)
  (abs
    (/ (apply '+
      (mapcar (function
(lambda (p1 p2) (* (+ (car p1) (car p2)) (- (cadr p1) (cadr p2))))
      )
      CoordsList
      (cons (last CoordsList) CoordsList)
      )
       )
       2.0
    )
  )
)
;(GetArea (Get3dVx (car (entsel "Select 3D polyline:"))))
Title: Re: How to know area
Post by: Adesu on January 16, 2008, 03:40:10 AM
Hi VovKa,
Your code is solution for 2d area not 3D
Title: Re: How to know area
Post by: CAB on January 16, 2008, 09:35:59 AM
How would you define the 3D area?
If you were to put faces on the pline using vertex you would need interior points and they are not defined.
Title: Re: How to know area
Post by: CAB on January 16, 2008, 09:43:15 AM
Well maybe I spoke too soon. :?
Title: Re: How to know area
Post by: SomeCallMeDave on January 16, 2008, 09:53:51 AM
But that area (refer to by some as the surface area as opposed to the  planimetric , or projected, planar area) will differ depending on how the 3dfaces area created. 

Creating/connecting the 3dfaces gets back to some of the previous discussions on triangulation and TIN creation.

I'm thinking that 10 people asked to calc the 3D area would come up the 10 different answers.   It isn't too difficult to calculate A 3d area.  Calculating THE 3d area, IMO,  a different task all together
Title: Re: How to know area
Post by: VovKa on January 16, 2008, 01:20:36 PM
Hi VovKa,
Your code is solution for 2d area not 3D

sorry to disappoint you, Adesu, and SomeCallMeDave is telling the thruth :)
Title: Re: How to know area
Post by: Joe Burke on January 17, 2008, 10:07:39 AM
The term "area" is not arbitrary. Within ACAD or Webstrer's dictionary it always refers to a calculation based on a flat plane. So there's no such thing as the "area" of a 3D pline which has points at various Z values.
Title: Re: How to know area
Post by: ElpanovEvgeniy on January 18, 2008, 02:07:58 AM
Hi! :)
Code: [Select]
(defun area_triangle_geron (d1 d2 d3 / d)
                           ;|
by ElpanovEvgeniy
18.10.2006

   Calculation area of a triangle under formula Geron
   
   Arguments:
   d1, d2, d3 - Lengths parties of a triangle
   
  (setq p1 (getpoint)
        p2 (getpoint)
        p3 (getpoint)
        d1 (distance p1 p2)
        d2 (distance p3 p2)
        d3 (distance p1 p3)
  ) ;_  setq

 
   Returne:
   (area_triangle_geron 3. 4. 5.) => 6.
  |;
 (setq d (* (+ d1 d2 d3) 0.5))
 (sqrt (abs (* d (- d d1) (- d d2) (- d d3))))
)
Title: Re: How to know area
Post by: CAB on January 18, 2008, 08:40:36 AM
Happy New Year Evgeniy.

So this would calculate area for the surfaces just like my picture?
Assuming a 3D point was used.
Title: Re: How to know area
Post by: VovKa on January 18, 2008, 12:03:39 PM
Geron's formula works excellent on 3d triangles.
the only problem left is the way we define these triangles.
see my attached drawing.
3d_area_of_ABC + 3d_area_of_CDA = 10488.1
3d_area_of_ABD + 3d_area_of_DBC = 10481.1
Title: Re: How to know area
Post by: CAB on January 18, 2008, 04:03:12 PM
Here we are back to the ten ways to calculate the area. :-o