Home > Software engineering >  Known more "dot" in a plane coordinates, and in which coordinates within a radius of a cir
Known more "dot" in a plane coordinates, and in which coordinates within a radius of a cir

Time:10-12



Known all small array at the "dot" coordinates (x (n), y (n)), and in which coordinates contains the most circle with radius of a scope,

Added: such as n is 0 to 20, "dot" is random, the coordinates of the size of the plane for the 20 * 20
Randomize
For n=0 To 20
X (n)=int (RND * 20)
Y (n)=int (RND * 20)
Next

CodePudding user response:

I am using exhaustive method, the code is a bit cumbersome (because I am a beginner, and bad at math!)
Came to the center coordinates are not necessarily only one so the return value is the number of,
I don't have the test code, if there is a problem continues!
 
Private Type PT
X As Long
Y As Long
End Type
Private Function GetPt (Pts) As PT) As PT () 'to a PT array to return to the center of the circle array
Dim the Up ((UBound (Pts)), 1) As an Integer, tmpUp As Integer
Dim tmpLong (UBound (Pts)) As Long
Dim I As an Integer, q As Integer
TmpUp=1
For I=0 To UBound (Pts)
For q=0 To UBound (Pts)
If I & lt;> Q Then
TmpLong (q)=CPt (Pts (I) and Pts (q))
End the If
Next
TmpUp=GetLongLenth (tmpLong)
For I=0 To UBound (Pts)
If the Up (I, 0) & lt;=tmpUp Then
The Up (I, 0)=tmpUp
The Up (I, 1)=I
The Exit For
End the If
Next
Next
Dim tmpUpNum As Integer
For I=0 To UBound (Pts)
If the Up (I, 0) & lt;> The Up (I + 1) Then
TmpUpNum=I
The Exit For
End the If
Next
Dim RPt (tmpUpNum) As PT
For I=0 To tmpUpNum
RPt (I)=Pts (Up (I, 1))
Next
GetPt RPt=
End the Function
Private Function CPt (Pt1 As PT, Pt2 As PT) As Long
CPt=((Pt1. X-ray Pt2. X) ^ 2 + (Pt1. Y - Pt2. Y) ^ 2) ^ (1/2)
End the Function
Private Function GetLongLenth (tmpLong ()) As Long As the Integer
Dim tmpNum As an Integer, tmpNum1 As Integer
Dim I, q
For I=0 To UBound (tmpLong)
TmpNum1=0
For q=0 To UBound (tmpLong)
If q & lt;> I And tmpLong (I)=tmpLong (q) Then
TmpNum1=tmpNum1 + 1
End the If
Next
If tmpNum1 & gt; TmpNum Then
TmpNum=tmpNum1
End the If
Next
GetLongLenth tmpNum=
End the Function

CodePudding user response:

The return value is an array of the above have the wrong number

CodePudding user response:

Kiss, ah, ah I know exhaustive method, if it is the whole desktop resolution size, 1024 * 768 * 20 that tends to more than one thousand cycles

CodePudding user response:

reference my3580 reply: 3/f
ah, exhaustive method I know ah, if it is the whole desktop resolution size, 1024 * 768 * 20 that will be more than one thousand cycles


Can see you did not understand the code, the distance of the center to the circumference of a circle are equal, on the basis of this,
GetPt function: calculate the distance between each dot, and then determine that a dot to other dots distance equal to the value most times, and then return to the dot,
Have some cases have equal number of equal distance from a lot of dots to other dots (i.e. by other centered on some dot dot radius is the distance to the center of the circle) so the answer may not be only one, so I use the return value is the PT types of arrays,

CodePudding user response:

For an example calls!!!!
Dim tmpPt () as Pt, RtmpPt () as Pt
'here in the random dot afferent tmpPt
RtmpPt ()=GetPt (tmpPt)

For I=0 to ubound (RTMPPT)
Msgbox "the first" & amp; I & amp; "With radius range contains the most are the coordinates of the center of the circle" RTMPPT (I) x & amp; ", "& amp; RTMPPT (I).
yNext

Code didn't check you try estimates that there is no problem

CodePudding user response:

Computing the most basic method, is exhaustive,

For most, it is difficult to optimize, if is the least, if the current item is more than the existing minimum counted, can stop counting, and most are not,

Therefore, this problem will require some "intelligent" processing, exclude some points not be exhaustive,

, for example, you can be the minimum and maximum coordinates X and Y coordinates of n rule out, because they are no other points, one side is an unlikely therefore contains most, of course, if these points are evenly distributed, this optimization is not applicable,

In short, when it comes to "optimization", will be closely associated with specific issues,

CodePudding user response:

And an optimization method, whether in the exhaustion of all other points in the current point within a radius of one, can rule out X or Y coordinates is greater than the difference between the radius of points, and don't have to calculate the distance between two points,
  • Related