[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

2081.0. ""Fence" Area problem..." by DPE1::TATARA (Eric Tatara PK03 223-1439) Thu Mar 27 1997 13:43

This problem deals with 2-dimensional closed areas, all made up of straight
line segments.  Areas can either be "fences" or they are not "fences".  An area
is a fence if it overlaps itself in a way that seperates a region inside the
fence from outside the fence.

Is there a fool-proof method for determining if an area is a "fence" or not?
Secondly, is there a way to determine if a specific point is inside the fence?

-----------------
|               |
|     ------    |
|     |    |    |
|     |    |    |
-------    ------
This area is not a fence.

2--------------------3
|                    |
|   9------------8   |
|   |            |   |
|   |            |   |
|   |            |   |
| 6-A------------7   |
1-C-B                |
  5------------------4
This area is a fence.
The area connects points 1,2,3,4,5,6,7,8,9,B then back to 1.
The region 7,8,9,A,7 would be considered "inside the fence".
Obviously, any point outside 1,2,3,4,5,C,1 would be considered "outside the
fence".
A point neither inside nor outside the fence is considered to be "within the
fence wall", eg, the midpoint between points 4 and 7 is "within the fence wall".

We have odd/even algorithms which can be used to determine if a point lies
"within the fence wall".  But this isn't quite what we're looking for.  Consider
the midpoint between 7 and 9.  An odd/even algorithm would consider that point
as being "outside" the fence.  We're looking for that point to be "inside".

Ideal would be an algorithm that determines if an area is a fence, and whether
a point is located anywhere within or not.  It does not matter how the
algorithm handles points "within the fence wall".

This is not a puzzle that I know the answer to, but is an actual work-related
problem.

Thanks for any help,
-- Eric
T.RTitleUserPersonal
Name
DateLines
2081.1PArt 2WIBBIN::NOYCEPulling weeds, pickin' stonesFri Mar 28 1997 10:0010
If you know (somehow) that you have a fence, can't you extend
the odd-even algorithm to count mod 4, to tell you whether
your point is inside it?  

If the final count is 1 or 3, you're "within the wall".
If the final count is 0, you're outside the fence.
If the final count is 2, you're inside the fence.

You need to be careful with the boundary cases, just as for
the normal odd-even algorithm.
2081.2Yes!DPE1::TATARAEric Tatara PK03 223-1439Mon Mar 31 1997 13:4210
Thank you!

I think that will do it...

We expect fence areas to be generally well-behaved...so to test that an area
is a fence, I anticipate that it will be okay to locate areas that have any
segments overlapping or intersecting other segments within the same area.

Thanks again,
-- Eric
2081.3get rid of interior edges, then use odd/evenTPOVC::BUCHANANRice = Red + IceMon Mar 31 1997 23:1073
(0) With respect, I don't think that the "solution" in .1 works

	Just take the example fence given in .0, and draw a line to the
centre starting from approximately the South-West corner. The line will
cross the boundary 4 times, and yet the region in the centre is meant to
be "inside" the fence.


(1) Clarification of problem statement needed.

	A closed curve comprising a finite number of straight line segments 
partitions the plane into a finite number of regions. All but one of these
regions is a polygon of finite area. The other region (the "outside") 
is of infinite area. 

	.0 tries to define the notion of a fence, distinguishing between 
polygons which are "inside" and polygons which are "in the wall". The 
definition given of a "fence" is descriptive rather than prescriptive and is 
actually circular! :-)

	For instance: are the following intended to be examples of fences:

A    B    C
+----+----+
|   / \   |
| D<   >E |
|   \ /   |
+----+----+
F    G    H 	 

	(a) if the closed path is A-B-E-G-H-C-B-D-G-F-A?
	(b) if the closed path is A-B-D-G-H-C-B-E-G-F-A?

	Anyway, I don't think that's too important. Your basic problem seems
to be identifying those points which are outside. I will leave it to you to
decide which of the other points are inside vs in the wall.


(2) A solution to Part 2.

	What you need to do is to remove all the interior edges (e.g.: BD,
BE, DG & EG in the above picture). Then you just apply the odd/even argument
to the edges that remain.

	There is a simple way to do this. First find a point on the perimeter
of the shape. Then trace round, identifying all the line segments that you
pass along. To be more formal...

	Let p_i = (x_i,y_i) be points for i = 0...n. Specify that p_0 & p_n are
the same. Let A->B be the notation for the directed line segment linking
point A to point B. Let l_i = p_(i-1)->p_i. Then the set of n l_i defines the
closed curve that we are interested in. 

	Let x = min(x_i) over i. Let X = max(x_i) over i. Similarly define y
and Y. Let d be very small. Then K = (x-d,y)->(X+d,Y) will cross the closed
curve. Find the intersection between K and l_i for each i at point Z_i. Find
the nearest of the Z_i to (x-d,y). Call it Q_0. That is our starting point on 
the perimeter.

	Q_0 lies on some line segment l_j(0). Find the intersection point
between each l_i and (Q_0,p_j(0)). At least one such point must exist. Find
the nearest of these intersection points to Q_0. Call that point Q_1.

	Q_1 lies on some l_j(1). Find the intersection point between each
l_i and (Q_1,p_j(1)). The nearest one to Q_1 is Q_2.

	Just iterate this to get Q_3,...Q_m, until you come back to Q_0. Then 
the Q_k define the outline of the fence, and you can use the odd/even argument 
to find out whether any point lies outside the shape.

Hope this is of use in your work,
Cheers,
Andrew.