Anyone written a lisp to divide 4 sided shape into two equal areas with vertical line?

Discussion in 'AutoCAD' started by James Maeding, Feb 2, 2005.

  1. so take 4 points that make a 4 sided closed shape and find a vertical line that divides them into two equal areas.
    Anyone done this?
    thx
    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Feb 2, 2005
    #1
  2. Can you post an image?
     
    Luis Esquivel, Feb 2, 2005
    #2
  3. Luis Esquivel, Feb 2, 2005
    #3
  4. James Maeding

    Bill DeShawn Guest

    Only for rectangles. Not for trapezoids or other polygons.

    --
    Bill DeShawn

    http://my.sterling.net~bdeshawn

    that divides them into two equal areas.
     
    Bill DeShawn, Feb 2, 2005
    #4
  5. James,
    Is the dividing line "always" a vertical line or is it in any direction?
    Alan Henderson @ A'cad Solutions

    that divides them into two equal areas.
     
    Alan Henderson @ A'cad Solutions, Feb 2, 2005
    #5
  6. Hi James,

    I wish you hadn't asked this question - My mind has been reverting to it all
    day. :)

    Eventually I couldn't resist sketching on some graph paper.

    For $25 I'd go straight to Luis' site and buy his program - get all the
    extra functionality he offers and get on with my life.

    However, an almost* general method of solution is to divide the rectangle
    into three with vertical lines through the two inner vertices. (*If either
    of the east pair of sides or the west pair are re-entrant this model needs
    more thinking)

    Check the sizes of each of the end triangles and see if either is more than
    half the area of the original rectangle. If it is, then the solution is a
    direct computation inside that triangle (by solving the quadratic equation
    for the width to give the required area).

    If it isn't then the solution is in the remaining rectangle with two
    vertical sides and a direct solution is again available - picture warping
    this rectangle till the bottom side is horizontal and you'll see what I
    mean.

    An easy way to get the area of a rectangle without any computation in VBA at
    least, is:

    Sub fred()

    Dim op As AcadLWPolyline
    Dim p(0 To 7) As Double
    p(0) = 1
    p(1) = 1
    p(2) = 10
    p(3) = 2
    p(4) = 3
    p(5) = 12
    p(6) = 11
    p(7) = 0
    Set op = ThisDrawing.ModelSpace.AddLightWeightPolyline(p)
    With op
    p(0) = .Area
    .Delete
    End With
    End Sub


    Another interesting outcome of my sketching was that it appears (don't take
    this as true) that if you create a series of inner rectangles - each joining
    the midpoints of the sides of the previous one, you end up near the centroid
    of the original rectangle.
    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Feb 2, 2005
    #6
  7. You must mean "quadrilateral" rather than "rectangle." If it's really a
    rectangle, it's easy (a vertical line through the point halfway between
    opposite corners). It's the NON-rectangular quadrilateral that's harder. I
    guess the line through the centroid of a region isn't going to be the
    answer, is it (too easy)?
     
    Kent Cooper, AIA, Feb 2, 2005
    #7
  8. Laurie Comerford, Feb 2, 2005
    #8
  9. I spent about 3 hours last night and this morning working on the problem.
    I could only get this to work using an iteration method.

    Here is what I came up with -

    ;=========================================
    ; Subdivide 4-side Polygon to equal areas
    ; Copyright (C) 2005 A'cad Solutions
    ; Alan R. Henderson
    ; All Rights Reserved
    ; Website: www.acadsolutions.biz
    ;=========================================

    ;GETAREA
    ; 1. Pick 4 corners of polygon
    ; 2. Pick new dividing line at final angle for division
    ; Line must be through opposite sides in direction of 1st to 2nd corner
    of polygon
    ;DIVAREA
    ; 1. Offset original dividing line by starting OFFSET amount (default set to
    0.1)
    ; If AREAS are with (* OFFSET 10), then change OFFSET to (/ OFFSET 10.0)
    ; Keep offseting until areas are within AREAOK amount (defualt set to
    0.00000001)
    ; The smaller the AREAOK amount the longer the program runs

    (defun CALC_AREA (PP1 PP2 PP3 PP4 /)
    (setq D13 (distance PP1 PP3))
    (setq D24 (distance PP2 PP4))
    (setq R13 (angle PP1 PP3))
    (setq R24 (angle PP2 PP4))
    (setq R31 (angle PP3 PP1))
    (setq R42 (angle PP4 PP2))
    (cond
    ((equal (- R42 R13) (- R24 R31) 0.00000001)
    (setq AREA (* 0.5 D13 D24 (abs (sin (- R42 R13)))))
    )
    ((equal (- R13 R24) (- R31 R42) 0.0000000001)
    (setq AREA (* 0.5 D13 D24 (abs (sin (- R13 R24)))))
    )
    (T
    (getstring "\nProblems with CALC_AREA...")
    (exit)
    )
    )
    )

    (defun FIND_AREAS ()
    (setq PX nil PS nil AR1 nil AR2 nil)
    (if (inters P1 P2 P5 P6 T) (setq PS (append PS (list "12")) PX (append PX
    (list (inters P1 P2 P5 P6 T)))))
    (if (inters P2 P3 P5 P6 T) (setq PS (append PS (list "23")) PX (append PX
    (list (inters P2 P3 P5 P6 T)))))
    (if (inters P3 P4 P5 P6 T) (setq PS (append PS (list "34")) PX (append PX
    (list (inters P3 P4 P5 P6 T)))))
    (if (inters P4 P1 P5 P6 T) (setq PS (append PS (list "41")) PX (append PX
    (list (inters P4 P1 P5 P6 T)))))
    (cond
    ((and (= (car PS) "12") (= (cadr PS) "34"))
    (setq AR1 (CALC_AREA P1 (cadr PX) (car PX) P4))
    (setq AR2 (CALC_AREA (cadr PX) P2 P3 (car PX)))
    )
    ((and (= (car PS) "23") (= (cadr PS) "41"))
    (setq AR1 (CALC_AREA P1 P2 (car PX) (cadr PX)))
    (setq AR2 (CALC_AREA P3 P4 (cadr PX) (car PX)))
    )
    )
    (princ)
    )

    (defun C:GETAREA (/ P1 P2 P3 P4 P5 P6 DONE AR1 AR2 LAR1 LAR2 ANG OFFSET
    AREAOK DON PS PX)
    (setvar "OSMODE" 1)
    (setq P1 (getpoint "\nPick 1st Point ? "))
    (setq P2 (getpoint P1 "\nPick 2nd Point ? "))
    (setq P3 (getpoint P2 "\nPick 3rd Point ? "))
    (setq P4 (getpoint P3 "\nPick 4th Point ? "))
    (setvar "OSMODE" 0)
    (setq P5 (getpoint "\nPick 1st Point of Dividing Line ? "))
    (setq P6 (getpoint P5 "\nPick 2nd Point of Dividing Line ? "))
    (grdraw P5 P6 1)
    (setq DONE nil LAR1 nil LAR2 nil ANG (/ pi 2))
    (setq OFFSET 0.1) ;starting offset amount
    (setq AREAOK 0.00000001) ;final equal area amount
    (CALC_AREA P1 P2 P3 P4)
    (FIND_AREAS)
    (while (not DONE)
    (setq LAR1 AR1 LAR2 AR2)
    (setq P5 (polar P5 (+ (angle P5 P6) ANG) OFFSET))
    (setq P6 (polar P6 (+ (angle P5 P6) ANG) OFFSET))
    (FIND_AREAS)
    (if (and (= (type AR1) 'real) (= (type AR2) 'real))
    (cond
    ((equal AR1 AR2 (* OFFSET 100.0))
    (setq OFFSET (/ OFFSET 10.0))
    )
    ((equal AR1 AR2 AREAOK)
    (setq OFFSET (/ OFFSET 10.0))
    (setq DONE T)
    )
    ((and LAR1 LAR2 (< AR1 AR2) (< AR1 LAR1))
    (setq ANG (+ ANG pi))
    (setq DONE nil)
    )
    ((and LAR1 LAR2 (< AR2 AR1) (< AR2 LAR2))
    (setq ANG (+ ANG pi))
    (setq DONE nil)
    )
    )
    (progn
    (princ "\nProblems with FIND_AREAS....")
    (exit)
    )
    )
    )
    (setvar "OSMODE" 0)
    (if PX (command "PLINE" (car PX) (cadr PX) "") (princ "\nProblem with PX
    value.."))
    (princ)
    )
     
    Alan Henderson @ A'cad Solutions, Feb 2, 2005
    #9
  10. Gary, What do you mean by horizontal or vertical? Alan
     
    Alan Henderson @ A'cad Solutions, Feb 2, 2005
    #10
  11. James Maeding

    Gary Fowler Guest

    Works horizontally but not vertically.

    added (command "redraw")

    Gary
     
    Gary Fowler, Feb 2, 2005
    #11
  12. James Maeding

    Gary Fowler Guest

    I get different areas when picking the two dividing line points; picking
    horizontally
    versers picking vertically.

    After picking the four points, I tried picking the next two points in
    different directions.
    The four points picked were for an unequal sided box.
     
    Gary Fowler, Feb 2, 2005
    #12
  13. wow, 13 replies! too cool.

    For those that were asking for clarification, the four points can be any four.
    I guess to simplify things a bit, the shape is really never like a V.
    That is, a vertical line wil never split the shape into more than two other shapes.

    Whether the solution works for a horizontal or vertical line does not matter, I can temporarily flip points around if
    that was an issue, so I could solve either case.

    I'll look at the code more, I just got back into my newsreader this am.
    thanks

    James Maeding <jmaeding at hunsaker dot com>
    |>so take 4 points that make a 4 sided closed shape and find a vertical line that divides them into two equal areas.
    |>Anyone done this?
    |>thx
    |>James Maeding
    |>jmaeding at hunsaker dot com
    |>Civil Engineer/Programmer

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Feb 3, 2005
    #13
  14. Now that I think of it, this is the same as asking for the center of gravity point for any 4 sided shape.
    The x value would be the vertical line and y would be the horizontal.
    combine those and you have a point about which you can calc any angle dividing line.

    There absolutely must be a formula out there for figuring this given a list of points forming a closed shape.
    I bet this works out to be simple once we find that algorythm

    James Maeding <jmaeding at hunsaker dot com>
    |>so take 4 points that make a 4 sided closed shape and find a vertical line that divides them into two equal areas.
    |>Anyone done this?
    |>thx
    |>James Maeding
    |>jmaeding at hunsaker dot com
    |>Civil Engineer/Programmer

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Feb 3, 2005
    #14
  15. nope, center of gravity does not work.
    I made a solid and listed the center of mass, then drew a line and made two plines.
    the areas are not equal.
    this is because the areas are weighted by the dist from the CG point, no good

    James Maeding <jmaeding at hunsaker dot com>
    |>Now that I think of it, this is the same as asking for the center of gravity point for any 4 sided shape.
    |>The x value would be the vertical line and y would be the horizontal.
    |>combine those and you have a point about which you can calc any angle dividing line.
    |>
    |>There absolutely must be a formula out there for figuring this given a list of points forming a closed shape.
    |>I bet this works out to be simple once we find that algorythm
    |>
    |>James Maeding <jmaeding at hunsaker dot com>
    |>|>so take 4 points that make a 4 sided closed shape and find a vertical line that divides them into two equal areas.
    |>|>Anyone done this?
    |>|>thx
    |>|>James Maeding
    |>|>jmaeding at hunsaker dot com
    |>|>Civil Engineer/Programmer
    |>
    |>James Maeding
    |>jmaeding at hunsaker dot com
    |>Civil Engineer/Programmer

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Feb 3, 2005
    #15
  16. James Maeding

    MP Guest

    I'd be surprised if there weren't a formula.
    Have you looked at the math sites already?

    gravity point for any 4 sided shape.
    list of points forming a closed shape.
    line that divides them into two equal areas.
     
    MP, Feb 3, 2005
    #16
  17. a few but not real deep yet.
    I keep thinking it has to be some variation of the center of gravity formula.
    I'll see

    "MP" <>
    |>I'd be surprised if there weren't a formula.
    |>Have you looked at the math sites already?
    |>
    |>"James Maeding" <jmaeding at hunsaker dot com> wrote in message
    |>|>> nope, center of gravity does not work.
    |>> I made a solid and listed the center of mass, then drew a line and made
    |>two plines.
    |>> the areas are not equal.
    |>> this is because the areas are weighted by the dist from the CG point, no
    |>good
    |>>
    |>> James Maeding <jmaeding at hunsaker dot com>
    |>> |>Now that I think of it, this is the same as asking for the center of
    |>gravity point for any 4 sided shape.
    |>> |>The x value would be the vertical line and y would be the horizontal.
    |>> |>combine those and you have a point about which you can calc any angle
    |>dividing line.
    |>> |>
    |>> |>There absolutely must be a formula out there for figuring this given a
    |>list of points forming a closed shape.
    |>> |>I bet this works out to be simple once we find that algorythm
    |>> |>
    |>> |>James Maeding <jmaeding at hunsaker dot com>
    |>> |>|>so take 4 points that make a 4 sided closed shape and find a vertical
    |>line that divides them into two equal areas.
    |>> |>|>Anyone done this?
    |>> |>|>thx
    |>> |>|>James Maeding
    |>> |>|>jmaeding at hunsaker dot com
    |>> |>|>Civil Engineer/Programmer
    |>> |>
    |>> |>James Maeding
    |>> |>jmaeding at hunsaker dot com
    |>> |>Civil Engineer/Programmer
    |>>
    |>> James Maeding
    |>> jmaeding at hunsaker dot com
    |>> Civil Engineer/Programmer
    |>

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Feb 3, 2005
    #17
  18. James Maeding

    ECCAD Guest

    Maybe I'm way off..but,
    Couldn't you calculate the 'centroid' point by merely
    drawing a line from (opposite) points, forming a X.
    The 'intersection' of that X should be the centroid ?

    Bob
     
    ECCAD, Feb 3, 2005
    #18
  19. nice! I'll get to the converting and post the code so everyone gets it.
    thanks

    "Kent Cooper, AIA" <>
    |>By the way, here's an illustration of how far the intersection of the
    |>diagonals can be from what you want. And this drawing is no
    |>approximation -- it's QUITE accurate. It has nice round number
    |>characteristics (ABCD is exactly 3, w is exactly 2, tanP is exactly 2, tanR
    |>is exactly 6). The y offset ends up being a nice clean (in lisp terms)
    |>
    |>(/ 3.0 (+ 2.0 (sqrt 3)))
    |>
    |>I calculated that to seven decimal places, and used that for offsetting AB.
    |>Boundary made two polylines whose areas were also equal to seven decimal
    |>places (1.5000000).

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Feb 4, 2005
    #19
  20. I have a surveyor that has a legal description saying "east half of said lot".
    This happens farily often apparently.
    To figure out what is the east, wes, north or south half, you have to split the area with a vertcal or horiz line.
    So I want to make a routine where you grab a pline and it will draw the vertical or horiz line splitting the area of the
    shape.
    thats it.

    "Luis Esquivel" <>
    |>Now... what exactly is what you are trying to do or come up?????????

    James Maeding
    jmaeding at hunsaker dot com
    Civil Engineer/Programmer
     
    James Maeding, Feb 4, 2005
    #20
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.