VB calculates the circle at three points and returns the outer circle at multiple points.

Source: Internet
Author: User
'The Runtime is about 5-7 seconds. 'Was previously written when the VB edition replied to a question.
 
 
VBScript code
Option explicit private type mypoint x As Double Y as double end type dim P (0 to 49) as mypoint dim smallcx as double dim smallcy as double dim smallr as double private sub form_load () 'set smallr to a very large smallr = 1E + 90 end sub private function equ (byval A as double, byval B as double) as Boolean If ABS (a-B) <0.000001 then equ = true else equ = false end if end function private function is_three_point_in_a_line (byval X1 as double, byval Y1 as double, byval X2 as double, byval Y2 as double, byval X3 as double, byval Y3 as double) as Boolean dim A as double, B as double, e as double A = (X1 + x2) * (x1-X2) + (Y1 + y2) * (Y1-Y2) B = (X3 + x2) * (X3-X2) + (Y3 + y2) * (Y3-Y2) E = (x1-X2) * (Y3-Y2)-(x2-X3) * (Y2-Y1) is_three_point_in_a_line = equ (E, 0) end function private sub calc_tpc (byval X1 as double, byval Y1 as double, byval X2 as double, byval Y2 as double, byval X3 as double, byval Y3 as double, CX as double, cy as double, R as double) dim A as double, B as double, e as double A = (X1 + x2) * (x1-X2) + (Y1 + y2) * (Y1-Y2) B = (X3 + x2) * (X3-X2) + (Y3 + y2) * (Y3-Y2) E = (x1-X2) * (Y3-Y2)-(x2-X3) * (Y2-Y1) Cx = (A * (Y3-Y2) + B * (Y2-Y1 )) /(2 * E) Cy = (A * (x2-X3) + B * (x1-X2)/(2 * E) r = sqr (x1-cx) * (x1-cx) + (Y1-cy) * (Y1-cy) end sub private function incircle (byval CX as double, byval Cy as double, byval R as double, byval PX as double, byval py as double) as Boolean dim L1 as double, l2 as double L1 = PX-cx L2 = Py-Cy if sqr (L1 * l1 + l2 * l2) <= r then incircle = true else incircle = false end if end function private sub commandelist click () CLS randomize timer dim I as long, J as long, K as long dim L as long dim CX as double, Cy as double, R as double dim count as long 'is 50 points, and displayed on the screen for I = 0 to 49 p (I ). X = RND * 2000 p (I ). y = RND * 2000 me. circle (P (I ). x, P (I ). y), 15, vbred next I 'calculates all circles for I = 0 to 49 for J = 0 to 49 for k = 0 to 49 if not is_three_point_in_a_line (P (I ). x, P (I ). y, P (j ). x, P (j ). y, P (k ). x, P (k ). y) then' three points can be used to calculate the circle calc_tpc P (I ). x, P (I ). y, P (j ). x, P (j ). y, P (k ). x, P (k ). y, CX, Cy, R' calculates whether all points are in the circle COUNT = 0 for L = 0 to 49 If incircle (CX, Cy, R, P (l ). x, P (l ). y) then count = count + 1 end if next l if Count = 50 then' all vertices in the circle if r <smallr then smallcx = Cx smallcy = Cy smallr = r end if end if next K next J next I 'draws the smallest circle (smallcx, smallcy), smallr, vbgreen end sub
 
  

  • Previous Article: Taoism 2 parsing STK
  • Next article: intersection of two straight lines
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.