Customer Service | Training | Contact Us
You are here: Home > User Forums > arcview 3.x users discussion forums > Thread Replies

ArcView 3.x Users Discussion Forums

ArcView GIS - Core program forum

convex hull, antipodal distance and minimum...   Dan Patterson Oct 18, 2002
Re: convex hull, antipodal distance and min...   William Huber Oct 18, 2002
Re: convex hull, antipodal distance and min...   Dan Patterson Oct 18, 2002
Re: convex hull, antipodal distance and min...   William Huber Oct 18, 2002
Re: convex hull, antipodal distance and min...   William Huber Oct 18, 2002
Re: convex hull, antipodal distance and min...   Dan Patterson Oct 18, 2002
Re: convex hull, antipodal distance and min...   William Huber Oct 18, 2002
Re: convex hull, antipodal distance and min...   William Huber Oct 18, 2002
Re: convex hull, antipodal distance and min...   Dan Patterson Oct 19, 2002
Report Inappropriate Content • Top • Print • Reply    
Subject convex hull, antipodal distance and minimum encompassing circle question 
Author Dan Patterson 
Date Oct 18, 2002 
Message Can someone direct me along the path.
I am working on some shape geometrics and have determined minimum bounding rectangles, convex hulls, antipodal distance (using Bill Huber's distance scripts) and am now trying to modify some code to return the minimum bounding circle. It works for the mostpart. Circles can be created using a radius specified by the half-distance of the largest antipodal axis and centering the circle at this point. in about 95% of the geometric shapes I apply this to, it works fine, it is the other 5% that bothers me. I know there are 3 point solutions to this problem but I would like to use tools at hand. The question then is what is the relationship between the original polygon bounds, the convex hull, the bounding rectangle (determined using a rotating calipers approach), the antipodal axis and distance. If I have to code 3 point solution, so be it
Dan 
  Geomatics, Carleton University, Ottawa, Canada 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: convex hull, antipodal distance and minimum encompassing circle question 
Author William Huber 
Date Oct 18, 2002 
Message Here is a randomized algorithm from de Berg et al., Computational Geometry with Applications, Springer-Verlag. Section 4.7. It consists of FOUR scripts, so watch for the script dividers and name the scripts appropriately.

The algorithm is simple but ingenious. The first script extracts the nodes from a shape and randomly permutes them. It calls the second script, "MiniDisk," to do the work.

MiniDisk grows the minimum enclosing disk point by point. The first two distinct points define a unique disk--they are the ends of its diameter. Each additional point that lies outside the current disk makes it larger. The task of enlarging the disk to include the previous points, while necessarily containing the new point on its boundary, is the job of "MiniDisk1".

MiniDisk1 begins with the circle defined by the first point in the list together with the special point which must be on the boundary. Then, in the same way MiniDisk grew the enclosing disk sequentially, MiniDisk1 also grows it, but this time with the constraint that the special point must always be on the boundary. At each step, a new point is considered. If it lies outside the current disk, then the disk must be enlarged. The enlarged disk must include the special point _and_ the new point on its boundary. The task of finding this disk is relegated to "MiniDisk2."

MiniDisk2 actually does some geometry: for each point in a list, it must compute the smallest circle containing it and two special points. That, fortunately, is straightforward.

The algorithm has expected running time O(N * lg(N)) where N is the number of vertices in the original shape.

All circles are represented as their centers and radii. This avoids the errors introduced by approximating circles as regular N-gons (ArcView represents circles as anything from a regular 16-gon to a regular 360-gon, depending on how it was constructed). 
 
'
' Smallest enclosing disk
'
' Returns the smallest disk enclosing a shape.
'
' SELF:  Shape
'
' Returns: {ptCenter, xRadius}
'
' WAH @QD
' AV 3.2a, 17 March 2002
'
' Comments: de Berg et al., Computational Geometry with 
' Applications, Springer-Verlag.  Section 4.7
'=============================================================='
theShape = SELF
if (theShape.Is(Polyline)) then
  lPts = {}
  for each lPtShape in theShape.AsList
    lPts = lPts + lPtShape
  end
  
elseif (theShape.Is(Multipoint)
  or theShape.Is(GeoCurve)) then
  lPts = theShape.AsList
  
elseif (theShape.Is(Rect)) then
  ptO = theShape.ReturnOrigin
  ptS = theShape.ReturnSize
  ptCenter = ptS / (2@2) + ptO
  xRadius = ptCenter.Distance(ptO)
  return {ptCenter, xRadius}
  
elseif (theShape.Is(Line)) then
  pt0 = theShape.ReturnStart
  pt1 = theShape.ReturnEnd
  ptCenter = (pt0 + pt1)/(2@2)
  return {ptCenter, ptCenter.Distance(pt0)}
  
elseif (theShape.Is(Circle)) then
  return {theShape.ReturnCenter, theShape.GetRadius}
  
elseif (theShape.Is(Oval)) then
  ptS = theShape.ReturnSize
  ptCenter = theShape.ReturnCenter
  return {ptCenter, ptS.GetX max ptS.GetY}
  
elseif (theShape.Is(Ellipse)) then
  ptCenter = theShape.ReturnCenter
  ptAxes = theShape.ReturnAxes
  return {ptCenter, (ptAxes.GetX max ptAxes.GetY)/2}
  
elseif (theShape.Is(Point)) then
  return {theShape.Clone, 0}

else
  return {Point.MakeNull, Number.MakeNull}
end
'
' Randomly permute lPts.
'
for each i in lPts.Count-1..1 by -1
  k = Number.MakeRandom(0, i+1) mod (i+1)
  ptI = lPts.Get(i)
  lPts.Set(i, lPts.Get(k))
  lPts.Set(k, ptI)
end
'
' Apply the algorithm.
'
return av.Run("MiniDisk", lPts)
' end of script
  

********
'
' MiniDisk
'
' SELF: List of points, already randomly permuted.
'
' Returns: {ptCenter, xRadius} for the
' smallest disc enclosing the points.
'
' Called by "Smallest enclosing disk".
'
' SELF must have at least two points.
'=================================================='
lPts = SELF

if (lPts.Count > 1) then
  ptCenter = (lPts.Get(0) + lPts.Get(1)) / (2@2)
  xRadius = ptCenter.Distance(lPts.Get(0))
  lPtVertices = {lPts.Get(0), lPts.Get(1)}
  
  if (lPts.Count > 2) then
    for each i in 2..(lPts.Count-1)
      ptP = lPts.Get(i)
      if (ptP.Distance(ptCenter) > xRadius) then
        lDisk = av.Run("MiniDisk1", {lPts, i-1, ptP})
        ptCenter = lDisk.Get(0)
        xRadius = lDisk.Get(1)
        lPtVertices = lDisk.Get(2)
      end
    end
  end
else
  ptCenter = lPts.Get(0)
  xRadius = 0
  lPtVertices = lPts.Clone
end

return {ptCenter, xRadius, lPtVertices}
' end of script


********
'
' MiniDisk1
'
' SELF: {
'   List of points,
'   Index of last point,
'   Point
' }
'
' Returns: {ptCenter, xRadius} for the
' smallest disc enclosing the points in the
' list with the point on its boundary.
'
' Called by "Minidisk".
'=================================================='
lPts = SELF.Get(0)
N = SELF.Get(1)
ptQ = SELF.Get(2)

ptCenter = (lPts.Get(0) + ptQ) / (2@2)
xRadius = ptCenter.Distance(ptQ)
lPtVertices = {lPts.Get(0), ptQ}

for each i in 1..N
  ptP = lPts.Get(i)
  if (ptP.Distance(ptCenter) > xRadius) then
    lDisk = av.Run("MiniDisk2", {lPts, i-1, ptQ, ptP})
    ptCenter = lDisk.Get(0)
    xRadius = lDisk.Get(1)
    lPtVertices = lDisk.Get(2)
  end
end

return {ptCenter, xRadius, lPtVertices}
' end of script


********
'
' MiniDisk2
'
' SELF: {
'   List of points,
'   Index of last point,
'   PointQ,
'   PointR
' }
'
' Returns: {ptCenter, xRadius} for the
' smallest disc enclosing the points in the
' list with PointR and PointQ on its boundary.
'
' Called by "Minidisk1".
'
' Modified 8/11/02: added if (xDelta <> 0.0).
'=================================================='
if (SELF = NIL) then
  lPts = {1@1}
  N = 0
  ptQ =0@0
  ptR = 1@0
else
lPts = SELF.Get(0)
N = SELF.Get(1)
ptQ = SELF.Get(2)
ptR = SELF.Get(3)
end

ptCenter = (ptR + ptQ) / (2@2)
xRadius = ptCenter.Distance(ptQ)
ptO = 0@0
ptB = ptR - ptQ
c2 = (ptR.Distance(ptO)^2 - (ptQ.Distance(ptO)^2))/2

for each i in 0..N
  ptP = lPts.Get(i) 
  if (ptP.Distance(ptCenter) > xRadius) then
    '
    ' Construct the disk through ptP, ptQ, and ptR
    ' by intersecting perpendicular bisectors of
    ' two sides of the triangle.
    '
    ' (When the points are not distinct, do a 
    ' special case.)
    '
    if (0@0 = ptB) then
      ptCenter = (ptP + ptQ) / (2@2)
      xradius = ptQ.Distance(ptCenter)
    else
      ptA = ptQ - ptP
      xDelta = ptA.GetX * ptB.getY - (ptA.GetY * ptB.GetX)
      if (xDelta <> 0.0) then
        c1 = (ptQ.Distance(ptO)^2 - (ptP.Distance(ptO)^2))/2
        x = (ptB.GetY * c1 - (ptA.GetY * c2)) / xDelta
        y = (ptA.GetX * c2 - (ptB.GetX * c1)) / xDelta
        ptCenter = x@y
        xRadius = ptCenter.Distance(ptP)
      end
    end
  end
end
'''MsgBox.Info(ptCenter.AsString + nL + xradius.AsString,"")
return {ptCenter, xRadius, {ptP, ptQ, ptR}}
' end of script
 
  --Bill Huber
Quantitative Decisions (http://www.quantdec.com
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: convex hull, antipodal distance and minimum encompassing circle question 
Author Dan Patterson 
Date Oct 18, 2002 
Message Thanks Bill
The question then would it be simpler to use the convex hull shape or the original shape? It is a matter of not wanting to repeat calculations in my final analysis. So this basically confirms that most shapes (using the terms loosely) would meet a 2point solution while others require a 3 point? or have I missed the point (pardon the pun)
Dan 
  Geomatics, Carleton University, Ottawa, Canada 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: convex hull, antipodal distance and minimum encompassing circle question 
Author William Huber 
Date Oct 18, 2002 
Message If you already have the convex hull, then compute its minimum enclosing disk. (Proof: the disk for the hull cannot be any larger than the disk for the original figure, because the hull is defined by a subset of the vertices. However, all points in the plane outside the hull's disk are outside the hull and consequently outside the original figure. Thus every point in the original figure is inside the convex hull's disk.)

It's difficult to say in what sense "most" shapes have a two-point solution. Only relatively skinny, smooth shapes have a minimum disk defined by their antipodal points. Thus, you cannot generally assume that the antipodal points define the diameter of the minimum enclosing disk. (The simplest counterexample is a near-equilateral triangle.)

Suppose you already have the convex hull in hand, and maybe even a pair of antipodal points. What you could do, for expedience, is construct the ArcView "circle" defined by the antipodal points and test whether the convex hull lies entirely within it. If so, then you have the minimum disk. (This works because the ArcView "circle" lies entirely within the true circle it is attempting to approximate.) Otherwise, proceed to compute the minimum disk from the convex hull using the de Berg et al. algorithm. 
  --Bill Huber
Quantitative Decisions (http://www.quantdec.com
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: convex hull, antipodal distance and minimum encompassing circle question 
Author William Huber 
Date Oct 18, 2002 
Message I am curious about what you mean by the "rotating calipers approach" to finding the MBR. I presume your MBR can have an arbitrary orientation (otherwise you would just use .ReturnExtent). In this case, in what sense is a bounding rectangle "minimum"? Is it minimum-area? Minimum-perimeter? Minimum largest side length? Minimum diagonal? Something else? 
  --Bill Huber
Quantitative Decisions (http://www.quantdec.com
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: convex hull, antipodal distance and minimum encompassing circle question 
Author Dan Patterson 
Date Oct 18, 2002 
Message Bill
I am determining minimum area and not the others. In brief, the orientation is determined by rotating the convex hull about the origin (tranlation and rotation stuff) so that one side at a time is parallel to the Y axis, the returnExtent is used to get the area, the loop is continued until a minimum area is found then returned. I haven't had any problems with returning MBR for area and I am sure that minimum perimeter, minimum and largest diameter can be oftained out of the loop since the extents are queries when one side is parallel with the y axis. (I have left out the fiddly bits, but I am sure that you get the drift). The problem arose when a student working for a colleague wanted to describe the type of "shape" that lakes (or any other spatial feature for that matter) in terms of "more rectangular" "more like a circle" "kind of elliptical" etc etc.

Dan 
  Geomatics, Carleton University, Ottawa, Canada 
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: convex hull, antipodal distance and minimum encompassing circle question 
Author William Huber 
Date Oct 18, 2002 
Message Yes, that's exactly the solution I have implemented. I called the result the "MABR", or minimum-area bounding rectangle. 
  --Bill Huber
Quantitative Decisions (http://www.quantdec.com
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: convex hull, antipodal distance and minimum encompassing circle question 
Author William Huber 
Date Oct 18, 2002 
Message Here's an example where the minimum bounding circle does not contact the shape's diameter at all. This might help clarify some of the relationships you ask for (and help in your testing).

It's a bilaterally symmetric pentagon with vertices at (z, -1/2), (-z, -1/2), (-0.98, 0), (0, 1), and (0.98, 0) where z is sqrt(3)/2 (0.866025 will do).

Its diameter is its intersection with the x-axis. Its minimum bounding disk is the unit circle at the origin. It was made by bending two of the sides of an equilateral triangle outward. 
  --Bill Huber
Quantitative Decisions (http://www.quantdec.com
   
Report Inappropriate Content • Top • Print • Reply    
Subject Re: convex hull, antipodal distance and minimum encompassing circle question 
Author Dan Patterson 
Date Oct 19, 2002 
Message Thanks Bill
On to the ellipse. By the way, I gound the computational geometry text on the bottom shelf of my bookcase, I have dusted it off and will have a read this weekend 
  Geomatics, Carleton University, Ottawa, Canada