LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Smallest circle around N points

Solved!
Go to solution

 

 

A few pictures may help-- and some clarification

Circle1.PNG

 In this frame we see how I chose the arbitrary median of [C] to determine the inner boundry of Orbit point O and its arbitrary starting point.  Simply O only needs to be outside the light green circle and point out there will do.

 

Circle2.PNG

 

Here I have constructed the "chords of interest" and identified all points on the circle (and some "trivial" points) (in this ex 1 point is trivial (that is inside the circle)

 

Nex we examine the angles of the chords at the vertices. They will either be obtuse, right or accute If the angle is obtuse (as @2) a circle drawn through them will be too small as seen here  (because we have found the smallest circle containing those three points Smiley Wink

Circle3.PNG

However If the angle is RIGHT Or accute as seen @1 we can draw the circle though these three points at by selecting the correct origin shown below

 

Circle4.PNG

 

The trick to this is that the smallest circle solution must not have all of its points on the circumferance in one hemisphere (except at the special case where excatly two pointsare on the circumference )  .  Rotate the top point in [C] CCW on the circumference. the "Chord of interest" rotates rotates CCW at half the radiial velocity and angle 1 becomes more accute BUT, the intesection of the bisecting lines does not change (although at some point a Flip occurs as the point is uneclipsed earlirer in the Orbit)

 

 

 


"Should be" isn't "Is" -Jay
Message 11 of 39
(4,093 Views)
PS- This has been PURE deductive reasoning- although I believe I've backed into the equivalent of the Elzinga-Hearn Algorithm but with a laymans description and a totally different approach

"Should be" isn't "Is" -Jay
Message 12 of 39
(4,094 Views)

RWiersma wrote:

Jeff,

 

Thank you for the informative post. I'm working to make a VI implementation of your notes, as we speak.

 


 

 


And as for a LV implementation----

Ben? 

Christian?  HELP


"Should be" isn't "Is" -Jay
0 Kudos
Message 13 of 39
(4,089 Views)

Circle5.PNG

Perhaps the way to get to this the easiest:

Triangles 

  • ABC
  • ABD
  • ACD
  • BCD

Are formed from the points we found. 

  • the circle defined by Obtuse triangle ABC will not enclude point D Refer to your Trig notebook: an obtuse triangle can be inscribed inside a single hemishere of a circle a right triagle has exactly pi radians) and  we noted earlier that the arc between all points on the circumferance must be >=pi*r 
  • Likewise Obtuse triangle BCD will not enclude point A

However, Acute triangles ABD and ACD do meet the the Arc >= pi*r requirement and circles inscribed about Them will define your smallest circle

Circle6.PNG


"Should be" isn't "Is" -Jay
0 Kudos
Message 14 of 39
(4,066 Views)

Interesting little problem.  During a coffee break I implemented the EH algorithm just for fun.  Worked entirely too well from the first time I ran it so something is probably terribly wrong with my trig or the code.  Seems to do the job, every once in a while it hangs due to what appears to be a floating point error.

 

Enjoy.  (BTW I used my automatic formula generation code for the circumscribed triangle VI, so that mess is not entirely my fault.)

 

Algorithm details taken from the original link.

 

 

Message 15 of 39
(4,035 Views)

Darin.K wrote:

Interesting little problem. 

Crap,! I sweated my skull off!!!

.  During a coffee break I implemented the EH algorithm just for fun.



(bows) " Master, I am not worthy"



  Worked entirely too well

 


 

Pretty Well indeed (bows)

 


 so something is probably terribly wrong with my trig or the code.

 


In a polar coorodinate plane

Where O = origin

T(heta) = angle

And r= radius

Place points at:

A = r,180

B=  r,0

c= r</1/pi/2<0,90

d =-r</pi/2<0,180

 

Set up : Special case  where the distribution is ovoid in along the major axis A-B

 

Solve:

 

 every once in a while it hangs due to what appears to be a floating point error.

 

Enjoy. 



But-  WOW! nice math (seriously)

 

 


"Should be" isn't "Is" -Jay
Message 16 of 39
(4,027 Views)

Jeff, I have only scratched the surface of your construction, but my compliments, indeed.  It will take a couple of more coffee breaks (and ensuing caffeine rush) to get my brain around it.   For the classic algorithm, a lot of the work is already done, but there still are a few tasks which are much easier put into words than LV expressions.  "Extend the diameter through point X and choose point Y or Z which is in the opposite half-plane of Point W..."

 

I wish I had these posts on my recent plane trip, it would have been great fun to work through with only pen and paper.   As for your willingness to sweat your skull off over this problem, you have my utmost respect.

Message 17 of 39
(4,017 Views)

Darin-

 

Your implementation of the EHA is brilliant! Your code in NewPoint.vi is well done.

My version of the program looks similar for steps 1-3, but yours is far more clean and tidy than mine.

 

I was stuck on Step 4, building the PL and R points.

 

Specifically, my learning experience came from searching an array for Max (or Min). After seeing this, it seems so elementary. I kept putting the arrays into for loops, and keeping a water mark and recording the (i) at the same time. What a waste of time!

 

Thank you for your hard work!

 

 

Jeff-

 

Your efforts put into this situation are highly appreciated, and commendable. I have to admit, I was pulling out old textbooks to remember the first thing about polar coordinates! 🙂

 

I attempted to implement your logic several different times, but I think my major confusion was trying to work in radians, when I don't have a solid understanding of them. I use degrees for everything in my line of work, and it was my own inflexibility that brought me down, here.

 

Thank you very much for your skull-sweating 🙂

Message 18 of 39
(3,979 Views)

All points (x,y) on a circle that is centered at the origin obey the relationship x^2 + y^2 = r^2, where r is the radius. If the center of the circle is at xo,yo, then the points obeys the relationship (x-xo)^2 +(y-yo)^2 = r^2. If you have three points, (x1,y1), (x2,y2), and (x3,y3),  you have three equations:

(x1-xo)^2 + (y1-yo)^2 = r^2      Eq1

(x2-xo)^2 + (y2-yo)^2 = r^2      Eq2

(x3-xo)^2 + (y3-yo)^2 = r^2      Eq3

and three unknowns xo, yo, and r. 

 

Therefore, with three points, the circle is completely defined and r can be solved uniquely (ignoring neqative values for r). If you have more than 3 points, you can not be assured that they all fall on a circle. If you have only 2 points, the smallest circle that can be drawn through both is the circle with the diameter equal to the distance between them. 

 

The algebra to find r from 3 points is tedious but straight-forward. Just set the left side of Eq1 to the left side of Eq2, eliminating r^2. Then you can solve for xo in terms of yo and known values. Then do the same for Eq2 and Eq3 and solve for yo in terms of xo. Substitute the value for xo found previously into this latter equation and you have your answer for yo. If I didn't make a mistake, it should look like

 

yo = {y3^2  - y2^2 + x3^2 - x2^2 + (x2-x3)*(x2^2 - x1^2 + y2^2 - y1^2)/(x2 - x1)}/{2 * [(y3 - y2) - (x2 - x3)*(y1 - y2)/(x2 - x1)]} 

 

Then you just substitue this into the previous equation to get x0 and finally substitute both the values for xo and yo into any of the original equations to get r. 

 

0 Kudos
Message 19 of 39
(3,962 Views)

Circle7.PNG

Darin,

 

The weakness of my approach lies in determining the trivial Points.  in this example, Points C and D are "trivial" in that they form the obtuse angles ACB and ADB.   And thusly they do not define the circumference.  Although, it would be easy to construct an example where a "Trivial" point IS on the circumferance, the circle would be described sufficiently by the remaining points hence if ANY point forms any obtuse angle it can, and should, be dismissed from further analisys.

 

Your implementation DOES solve for this special case.  My gut analisys last evening suffered from lack of proper investigation. Your methodology of bisecting a triangle in "Circle from diameter.vi" is Briliant! (but really needs some documentation Smiley Very Happy

 

I now suspect your occasional "hangs" are related to the approach your use in step three at Acute Triangle.vi.  While I tested a few cases where the origin lies in line with two points and did not observe any "hanging", I suspect the dissmissal of right trianlges may be your culprit.  Rightness is  Very difficult to determine in a cartisean system limited to DBLs.  If you have any examples you've seen hang please post them.  Another possibile culprit is in Step two.  I suspect there could be cases where two identical points (or two points with identical "Max Distances" found from Check Points.vi) could infinetely swap back and forth between index 0-2.  

 

The only (ERROR?) I have found is the special case where Index[C]=1 :r=0 is correct in that a circle of "no" size contains a point however, Xc =0and Yc=0 places the null circle in the wrong location.  Xc=X[0] and Yc=Y[0] in this case.

Message Edited by Jeff Bohrer on 02-02-2010 11:10 AM

"Should be" isn't "Is" -Jay
0 Kudos
Message 20 of 39
(3,950 Views)