area calculation

Discussion in 'Cadence' started by Guenther Sohler, Oct 2, 2007.

  1. Is there a built-in
    cadence function to calculate the area of any
    polygon or rectangle in cadence ?

    i could do it myself but i am wondering if it already existed
     
    Guenther Sohler, Oct 2, 2007
    #1
  2. Guenther Sohler

    S. Badel Guest

    Is there a built-in
    There's such a function in the turbo toolbox, if I remember correctly.

    No public SKILL function that I'm aware of, though.


    Stéphane
     
    S. Badel, Oct 2, 2007
    #2
  3. Guenther Sohler

    cadence Guest

    see if this works for you???

    (inScheme
    (defun jenPolygonArea (perim "l")
    (let ((ymin (apply 'min (mapcar 'cadr perim))))
    (let ((area (lambda (p1 p2)
    (times ((xCoord p1) - (xCoord p2))
    ((yCoord p1) + (yCoord p2) - ymin)))))
    (let ((total (area (car (last perim)) (car perim))))
    (foreach map pts perim
    (when (cdr pts)
    total = total + (area (car pts) (cadr pts))))
    (abs total / 2.0))))))
     
    cadence, Oct 5, 2007
    #3
  4. Guenther Sohler

    cadence Guest

    here is a slightly more faster version. The idea is that the function
    must calculate a lower bound.
    but sometimes you already know a lower bound. i.e., you might know
    the bbox and the bottom
    of the bbox of a polygon is a lower bound for the polygon.

    -jimka


    ;; ?ymin is any any lower bound of the polygon.
    ;; If you know the db polygon, you can use:
    ;; (jenPolygonArea d_polygon ?ymin (bottomEdge d_polygon))
    ;; If you only know the list of points, jenPolygonArea will
    automatically
    ;; calculate a sufficient lower bound for you:
    ;; (jenPolygonArea '((0 0) (0 1) (1 0) (1 0)))
    (defun jenPolygonArea (perim @key ymin "lg")
    (let ((ymin (or ymin (apply 'min (mapcar 'cadr perim))))
    (total 0))
    (foreach map pts (cons (car (last perim)) perim)
    (when (cdr pts)
    (let ((p1 (car pts))
    (p2 (cadr pts)))
    total = total + (times ((xCoord p1) - (xCoord p2))
    ((yCoord p1) + (yCoord p2) -
    ymin)))))
    (abs total / 2.0)))
     
    cadence, Oct 6, 2007
    #4
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.