Author Topic: How to get area?  (Read 5642 times)

0 Members and 1 Guest are viewing this topic.

litss

  • Guest
How to get area?
« on: October 18, 2011, 05:16:37 AM »
I have got a list of line ends, like ((pt1 pt2) (pt3 pt4) (pt5 pt6) ...). And these lines form a closed area (only one), but some of them connect by ends and others cross each other, which means it could be rectangle or "#".

How could I get the area of the closed area? I've tried: draw the lines->pick a point manually within the closed area->genrate a region->get the area. But here, a manual point is required.

If "regen" is the only way, how can I omit the "pick point" step? Or, there is another better way to solve the problem?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to get area?
« Reply #1 on: October 18, 2011, 05:59:54 AM »
Depending on how complex the shape defined is, and if you're only using lines: Then you could use the inters function to find those intersections, generate a LWPolyline from those points and get it's area property.

Of course you'd need to find the correct order for these intersections though, otherwise you could end up with a self-intersecting polyline. Thus your area would be smaller than it should.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: How to get area?
« Reply #2 on: October 18, 2011, 09:16:10 AM »
Depending on how complex the shape defined is, and if you're only using lines: Then you could use the inters function to find those intersections, generate a LWPolyline from those points and get it's area property.

If you have a set of points describing a simple (non-intersecting) polygon, you can use the equation from here to calculate the enclosed area, e.g.:

Code: [Select]
(defun PointArea ( lst )
    (/
        (abs
            (apply '+
                (mapcar
                    (function
                        (lambda ( a b ) (- (* (car a) (cadr b)) (* (car b) (cadr a))))
                    )
                    lst (append (cdr lst) (list (car lst)))
                )
            )
        )
        2.0
    )
)

litss

  • Guest
Re: How to get area?
« Reply #3 on: October 18, 2011, 09:17:13 PM »
Thanks U guys!

To irneb: :( I have tried to collect points before. But I have no idea how to arrange them in the right order. So I finally gave up that thought.

To Lee: Does ur routine require a arranged points-lst? I haven't tried it. If not, the same problem.


pBe

  • Bull Frog
  • Posts: 402
Re: How to get area?
« Reply #4 on: October 18, 2011, 11:45:39 PM »
USe something like this in conjunction with Lee's code

Code: [Select]
(defun c:test (/ sort_ ss i ent pts_ ll)
(defun sort_ (lst / a  mList intr)
    (while (setq a (car lst))
  (foreach itm (setq lst (vl-remove a lst))
  (if (setq intr (inters (car a)(cadr a)
                       (car itm)(cadr itm) ))
     (setq mList (cons intr mList))))
  )
  mList
    ) 
  (setq ss (ssget '((0 . "LINE"))))
  (repeat (setq i (SSLENGTH ss))
  (setq ent (entget (ssname ss (setq i (1- i))))
      )
  (setq pts_ (cons (list (cdr (assoc 10 ent))
  (cdr (assoc 11 ent))) pts_)))
(if (= (length  (setq ll (sort_ pts_))) 4)
    (princ (strcat "\nArea: "(rtos (pointarea (list (cadr ll)
(car ll)
(caddr ll)
(last ll)
   )
) 2 4)))
   )(princ)
  )

Hope this helps

litss

  • Guest
Re: How to get area?
« Reply #5 on: October 19, 2011, 09:24:19 PM »
Thx pBe!

I will try ur code soon. It must be helpful.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How to get area?
« Reply #6 on: October 20, 2011, 07:53:32 AM »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

litss

  • Guest
Re: How to get area?
« Reply #7 on: October 20, 2011, 11:40:43 AM »
To pBe: I've tried ur code. It works well with closed area with 4 lines. But failed with more than 4. I am not quite sure why.

To Lee: Ur code works. But it did require an arranged pts. Otherwise, returns unexpected value.

To alanjt: Thank you. Ur code is amzing. Though it is not perfectly meet my situation. I can't point out he vertex one by one to get the area. There are too many.

Thx again for all of u. I'll try to arrange the intersections. Then I will use Lee's code.


Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: How to get area?
« Reply #8 on: October 20, 2011, 11:57:14 AM »
To Lee: Ur code works. But it did require an arranged pts. Otherwise, returns unexpected value.

Yes, the points must outline the area, since the equation will only apply to simple (non-self-intersecting) polygons.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How to get area?
« Reply #9 on: October 20, 2011, 12:58:30 PM »
Why not use BPoly and pick a point within your intersecting lines and get the area from the created polyline?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

litss

  • Guest
Re: How to get area?
« Reply #10 on: October 20, 2011, 09:37:19 PM »
alanjt:  Well, to manually pick a point within the area is my current way. The difference is I generate a "region", not a pline. I just wanna improve and make it more automaticly.  Maybe I can try to find out a point within the area automaticly. That will do too.  Thx!

pBe

  • Bull Frog
  • Posts: 402
Re: How to get area?
« Reply #11 on: October 21, 2011, 12:56:12 AM »
To pBe: I've tried ur code. It works well with closed area with 4 lines. But failed with more than 4. I am not quite sure why.

Of course, its written that way to do as such  :)

Thx again for all of u. I'll try to arrange the intersections. Then I will use Lee's code.

Might as well :)

Tell you what, post an image or a dwg sample.




litss

  • Guest
Re: How to get area?
« Reply #12 on: October 21, 2011, 02:08:02 AM »
Here are the samples. I am wishing to get the areas of all shadowed automaticly while I "ssget" the lines at one time. It might be too difficult for me. So I am planning to "ssget" one by one :), without picking a point within it.

pBe

  • Bull Frog
  • Posts: 402
Re: How to get area?
« Reply #13 on: October 21, 2011, 03:02:26 AM »
Here are the samples. I am wishing to get the areas of all shadowed automaticly while I "ssget" the lines at one time. It might be too difficult for me. So I am planning to "ssget" one by one :), without picking a point within it.

Tell me this, if you're going to select the lines one by one anyway, you might as well pick a point rather than select the lines:
8 lines , 8 input
8 points, 8 input

Alanjt's posted link will take care of the area once you have the points in order, which is very likely so as you are picking the points in order


or why not?
Quote
Why not use BPoly and pick a point within your intersecting lines and get the area from the created polyline?

The plines generated by BPoly can be easily converted to a region and just one pick point.

we can play around with codes to suit your needs, but there are other options to consider first.

So give us an outline
How:<-------- sequence that is

What:<--- the result  (besides the area value of course)

 :-)



« Last Edit: October 21, 2011, 03:09:00 AM by pBe »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: How to get area?
« Reply #14 on: October 21, 2011, 03:08:54 AM »
I can think of a way using polar to figure out the direction around the shape for most of those. The problem one would be that Z shape.

As a test I tried figuring out if a hatch would work, though then you get all sorts of strange artifacts. So bang goes that idea. It seems your best bet is to use the boundary though trying to figure out the "internal" point would be very similar to trying to figure out the order of the intersections.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.