Adept Scientific - English
The world's best software and hardware for research, science and engineering.
flag arrow
clearclear

 Adept Store | register Join My Adept | Flags  
Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055  
UKdedksvnofi
Home
Products
Training
Events
 Buy Online
Downloads
Academic Discounts
Support
My Adept
International |  About Us |  Adept Scientific Blog |  Contact Us |  Press Room |  Jobs
Adept Scientific on Facebook Adept Scientific on Twitter Adept Scientific on YouBube Adept Scientific on LinkedIn


The Next Steps

• Ask us a question
• Buy Mathcad Now
• View Mathcad Pricing
• Download a Demo
• Download Mathcad Express
•  Request a Brochure
• Download a Brochure
• Find out about Training
• Meet Our Team
• Read our RSS Feeds

Learn More

Mathcad Home
Mathcad Prime 2.0
Migration Guide

Version Comparison Chart
Mathcad Enterprise
Mathcad for Education
Rave Reviews
Add-ons

System Requirements

Latest Information

New Features in Mathcad
Prime 2.0

Mathcad Express
Mathcad Prime 2.0 movies
Using Mathcad and Excel
Return on Investment

Service & Support

Frequently Asked
Questions

Search the Knowledge
Base

Join the Discussion List
Search the List Archive

List Archives >  Mathcad List Archive >  Archive by date >  This Month By Date >  This Month By Topic

[MATHCAD] Polygons (again)

Search email archive for  

[MATHCAD] Polygons (again)
Author: Chris Whitford    Posted: Wed, 29 Sep 1999 15:44:10 +0100
Earlier in the year there was some correspondence about finding if a point
is inside a polygon. I have recently had to code this into an application,
so I have had to take another look at it.

The basic principle is that if a line is drawn from the point, in any
arbitrary direction, and the number of times the line crosses the boundary
of the polygon is counted, then if the point is inside the count is odd,
otherwise it is even (this was posted by Mike Yuratich). The problem arises
when the line goes through a vertex, or the point is on an edge or vertex.
Because of the finite machine precision, one has to be very careful that
such a situation is counted correctly. The following algorithm does this, I
think.

First translate the coordinates to put the point at the origin, and take
the trial line to be on the +X axis, extending to infinity. Consider if the
line crosses the polygon edge from vertex 1 (x1,y1) to vertex 2 (x2,y2).

if ((y1 > 0 and y2 <= 0) or (y1 <= 0 and y2 > 0))
and (sign(y1 - y2) = sign(x2.y1 - x1.y2))
then count this as a crossing

The effect of this algorithm is:
a) if a vertex is at x>0, y=0, the edge will be counted if it is above the
X axis but not if it is below.
b) if the point is on the edge it will not be counted.
c) if a vertex is at x=0, y=0 neither edge ending at this vertex will be
counted.

This gives a consistent counting of crossings which ensures the correct
result. It also ensures that if a surface is covered with a collection of
polygons with common edges, a point on an edge or vertex will be located
unambiguously in one and only one polygon.

Chris Whitford

+----------------------------------------------------------------------+
+ Chris Whitford University of Leicester +
+ Tel: (44) 116 252 3496 Space Research Centre +
+ Fax: (44) 116 252 2464 Physics and Astronomy Department +
+ University Road +
+ http://www.star.le.ac.uk/ LEICESTER LE1 7RH +
+ UK +
+----------------------------------------------------------------------+

-------------------------------------------------------------
The Mathcad List - Discussion, Support & News
Contributions: /> To unsubscribe: Send in the body: unsubscribe mathcad
To: /> Hosted by: Adept Scientific http://www.adeptscience.com
List Archive: http://lists.adeptscience.co.uk/


Re: [MATHCAD] Polygons (again)
Author: Jim Irving    Posted: Thu, 30 Sep 1999 00:32:17 +0100
Dear Chris,
See my reply to an earlier question (copied herewith). It may be helpful to
you.

Regards,

Jim Irving

Dear Ronny,

This may be a bit late but I'm slowed down with a ruptured Achilles
tendon, in plaster and on crutches. Your question reminded me of a
similar problem I had when working
on earthquake hazards in the 1980's which was to determine
computationally in which regions of the British Isles the epicentres
were located from a list of position
co-ordinates. I solved it using the property that if a vector drawn from
the epicentre to the boundary is rotated through all the points defining
the boundary, returning
to the first point, the total angle swept out will be 360 degrees.
However, if the epicentre is outside the closed boundary the swept angle
will be zero. The simplest
solution was to use the properties of vectors to determine the swept
angles and hence the status "inbound" or "outbound". I think this is an
exact analogy to your
question and I have spent a little time producing a Mathcad 7 Pro
worksheet with the derivation of the formulae and a practical
illustration of the method. I have also
made a V 6 copy. Both these files are in the attached Zip file
Bounds.zip. I hope you find them useful - thanks for an interesting few
days "a la recherche du temps
perdus".

Regards,


Jim Irving



----- Original Message -----
From: Chris Whitford /> To: /> Sent: Wednesday, September 29, 1999 3:44 PM
Subject: [MATHCAD] Polygons (again)


> Earlier in the year there was some correspondence about finding if a point
> is inside a polygon. I have recently had to code this into an application,
> so I have had to take another look at it.
>
> The basic principle is that if a line is drawn from the point, in any
> arbitrary direction, and the number of times the line crosses the boundary
> of the polygon is counted, then if the point is inside the count is odd,
> otherwise it is even (this was posted by Mike Yuratich). The problem
arises
> when the line goes through a vertex, or the point is on an edge or vertex.
> Because of the finite machine precision, one has to be very careful that
> such a situation is counted correctly. The following algorithm does this,
I
> think.
>
> First translate the coordinates to put the point at the origin, and take
> the trial line to be on the +X axis, extending to infinity. Consider if
the
> line crosses the polygon edge from vertex 1 (x1,y1) to vertex 2 (x2,y2).
>
> if ((y1 > 0 and y2 <= 0) or (y1 <= 0 and y2 > 0))
> and (sign(y1 - y2) = sign(x2.y1 - x1.y2))
> then count this as a crossing
>
> The effect of this algorithm is:
> a) if a vertex is at x>0, y=0, the edge will be counted if it is above the
> X axis but not if it is below.
> b) if the point is on the edge it will not be counted.
> c) if a vertex is at x=0, y=0 neither edge ending at this vertex will be
> counted.
>
> This gives a consistent counting of crossings which ensures the correct
> result. It also ensures that if a surface is covered with a collection of
> polygons with common edges, a point on an edge or vertex will be located
> unambiguously in one and only one polygon.
>
> Chris Whitford
>
> +----------------------------------------------------------------------+
> + Chris Whitford University of Leicester +
> + Tel: (44) 116 252 3496 Space Research Centre +
> + Fax: (44) 116 252 2464 Physics and Astronomy Department +
> + University Road +
> + http://www.star.le.ac.uk/ LEICESTER LE1 7RH +
> + UK +
> +----------------------------------------------------------------------+
>
> -------------------------------------------------------------
> The Mathcad List - Discussion, Support & News
> Contributions: /> > To unsubscribe: Send in the body: unsubscribe mathcad
> To: /> > Hosted by: Adept Scientific http://www.adeptscience.com
> List Archive: http://lists.adeptscience.co.uk/
>

 Attachments:
 BoundsX.mcd


Previous by date: Re[2]: [MATHCAD] The Mathcad List and Adept, JasonCuadra
Next by date: Re: [MATHCAD] business, Ian Downie
Previous thread: RE: [MATHCAD] business, Shiner Adrian
Next thread: Re: [MATHCAD] business, Ian Downie



Ready to buy?

Mathcad Prime
Add to shopping basket
£ 1,020.00
Mathcad single user upgrades are no longer available. If you have an old Mathcad licence please contact your local office for options.

Featured Downloads

Mathcad Prime 2.0 Brochure
Mathcad Prime 2.0 Installation and Usage Information
Mathcad Prime 2.0 Installation and Administration Guide
Mathcad Prime 2.0 Keyboard Shortcuts
Mathcad Prime 2.0 Migration Guide
Mathcad Prime 2.0 FAQs

Latest Downloads

Mathcad Whitepaper: Standardizing Engineering Calculations in a Product Development System
Mathcad calculations for chemical and process engineering
Mathcad Case Study - The Rambøll Group deploys Mathcad Enterprise to manage calculations for 1,000 engineers
Mathcad Case Study - Meinhardt Facade Technology Adopts PTC's Mathcad to Improve Calculation Productivity
Mathcad Case Study - Bit Tips Asia Uses PTC's Mathcad in Railway Magnetic Field Calculations

Latest News

“Express delivery" of mathematical computation: Mathcad Express, free, forever
“Express delivery" of mathematical computation: Mathcad Express, free, forever
Mathcad Case Study - The Rambřll Group deploys Mathcad Enterprise to manage calculations for 1,000 engineers
Mathcad Case Study - GKN Revolves Around Aerospace Calculations
Mathcad Case Study - full steam ahead with Mathcad at MAN B&W Diesel AG
adept

Top of the Page

Popular Links: ChemDraw | ChemOffice | Data Acquisition | Data Analysis | EndNote | Mathcad | MathType | Quality Analyst | Reference Manager | VisSim

EU ePrivacy Directive | Our Privacy and Terms and Conditions Statement
All Trademarks Recognised. Copyright © 2013, Adept Scientific Ltd.
Site designed and maintained by Lyndon Ash

Adept Scientific | Amor Way | Letchworth Garden City | Herts | SG6 1ZA | Tel: +44 (0)1462 480055