• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. Determine a point is inside of a polygon or outside...

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 144
  • Views 18084
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Determine a point is inside of a polygon or outside...

Alvin Park
Alvin Park over 12 years ago

Hi.... This is KT PARK in Korea. 

Do you have any SKILL Command or code 

to determine a point is inside of a polygon or outside at Virtuoso Layout Suit?

 

 dbLayerInside or dbLayerOutside does not help.... T_T

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 12 years ago

    The fundamental algorithm looks very similar to my CCSpointInPolygon implementation in the solution I reference above - here's the same function with an "ab" prefix (I tend to convert the code to use a Cadence Customer Support prefix when publishing solutions). It's in a LISP-style, but you get the picture:

     

    /*************************************************************************
    *                                                                        *
    *                    (abPointInPolygon point points)                     *
    *                                                                        *
    *  Uses a ray casting approach to count if the number of intersections   *
    * is even or odd. Even means the point is outside, and odd means inside. *
    *     Returns t if inside the polygon. Note that the algorithm will      *
    *   ensure that for abutting polygons, it is only inside one of them.    *
    * So, for a single polygon, needs to be combined with abPointOnBoundary  *
    *                   to know if on boundary or inside.                    *
    *                                                                        *
    *                     Based on Jordan curve theorem                      *
    *           See http://en.wikipedia.org/wiki/Point_in_polygon            *
    *                                                                        *
    *************************************************************************/
    
    (defun abPointInPolygon (point points)
      (let (inside ptj 
    	       (testX (car point)) 
    	       (testY (cadr point)))
        (setq ptj (car (last points)))
        (foreach pti points
    	     (when
    	       (and
    		 (nequal
    		   (greaterp (yCoord pti) testY)
    		   (greaterp (yCoord ptj) testY))
    		 (lessp
    		   testX
    		   (plus
    		     (quotient
    		       (times
    			 (difference (xCoord ptj) (xCoord pti))
    			 (difference testY (yCoord pti))
    			 )
    		       (difference (yCoord ptj) (yCoord pti))
    		       )
    		     (xCoord pti)
    		     )
    		   )
    		 )
    	       (setq inside (null inside))
    	       )
    	     (setq ptj pti)
    	     )
        inside
        )
      )

     

    The one thing that's unnecessary in the code above is the conversion of the list into arrays - and in fact the populating of the arrays is inefficient as it uses a for loop together with nth. Most of the time that's probably not a big deal because the number of points in a polygon will often be small, but for large polygons the for loops will be O(N**2) rather than O(N) as it would have been if a foreach had been used.

    Kind Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 12 years ago

    The fundamental algorithm looks very similar to my CCSpointInPolygon implementation in the solution I reference above - here's the same function with an "ab" prefix (I tend to convert the code to use a Cadence Customer Support prefix when publishing solutions). It's in a LISP-style, but you get the picture:

     

    /*************************************************************************
    *                                                                        *
    *                    (abPointInPolygon point points)                     *
    *                                                                        *
    *  Uses a ray casting approach to count if the number of intersections   *
    * is even or odd. Even means the point is outside, and odd means inside. *
    *     Returns t if inside the polygon. Note that the algorithm will      *
    *   ensure that for abutting polygons, it is only inside one of them.    *
    * So, for a single polygon, needs to be combined with abPointOnBoundary  *
    *                   to know if on boundary or inside.                    *
    *                                                                        *
    *                     Based on Jordan curve theorem                      *
    *           See http://en.wikipedia.org/wiki/Point_in_polygon            *
    *                                                                        *
    *************************************************************************/
    
    (defun abPointInPolygon (point points)
      (let (inside ptj 
    	       (testX (car point)) 
    	       (testY (cadr point)))
        (setq ptj (car (last points)))
        (foreach pti points
    	     (when
    	       (and
    		 (nequal
    		   (greaterp (yCoord pti) testY)
    		   (greaterp (yCoord ptj) testY))
    		 (lessp
    		   testX
    		   (plus
    		     (quotient
    		       (times
    			 (difference (xCoord ptj) (xCoord pti))
    			 (difference testY (yCoord pti))
    			 )
    		       (difference (yCoord ptj) (yCoord pti))
    		       )
    		     (xCoord pti)
    		     )
    		   )
    		 )
    	       (setq inside (null inside))
    	       )
    	     (setq ptj pti)
    	     )
        inside
        )
      )

     

    The one thing that's unnecessary in the code above is the conversion of the list into arrays - and in fact the populating of the arrays is inefficient as it uses a for loop together with nth. Most of the time that's probably not a big deal because the number of points in a polygon will often be small, but for large polygons the for loops will be O(N**2) rather than O(N) as it would have been if a foreach had been used.

    Kind Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information