Sorry in advance, I'm struggling a bit with how to explain this... :)

Essentially, I've got a typical windows coordinate system (the Top, Left is 0,0). If anybody's familiar with the haversine query, like in SQL, it can get all points in a radius based on latitude and longitude coordinates.

I need something much simpler, but my math skills ain't all up to par! Basically, I've got random points scattered throughout about a 600x400 space. I have a need to, for any X,Y point on the map, run a query to determine how many other points are within a given radius of that one.

If that's not descriptive enough, just let me know!

Faster way to sum a list of numbers than with a for-loop?

## 1:

Calculating all possible sub-sequences of a given length (C#)

Use Pythagoras:.

Adding a separator to a list of items for display

Best match between two strings when the order or number of times a word appears is not important?

In other words the idea is to square both differences..

How can I improve this square root method?

Adding a separator to a list of items for display

`distance = sqrt(xDifference^2 + yDifference^2) `

Note that '^' in this example means "to the power of" and not C's bitwise XOR operator. Best match between two strings when the order or number of times a word appears is not important?

In other words the idea is to square both differences..

How can I improve this square root method?

Selecting a Unique Identifier in C for an Embedded Application

Slider Bar/Pins algorithm

## 2:

How would you develop a frequency-sorted list of the ten thousand most-used words in the English language?

Straightforward approach:. You can calculate the distance between to points using the Pythagorean theorem:.

`deltaX = x1 - x2 deltaY = y1 - y2 distance = square root of (deltaX * deltaX + deltaY * deltaY) `

Given point `x1,y1`

, do this for every other point (`x2,y2`

) to see if the calculated distance is within (less than or equal to) your radius.. If you want to make it speedier, calculate and store the square of the radius and just compare against `(deltaX * deltaX + deltaY * deltaY)`

, avoiding the square root.. ## 3:

Before doing the Pythagoras, you could also quickly eliminate any point that falls outside of the square that can fully contain the target circle..

`// Is (x1, y1) in the circle defined by center (x,y) and radius r bool IsPointInCircle(x1, y1, x, y, r) { if (x1 < x-r || x1 > x+r) return false; if (y1 < y-r || y1 > y+r) return false; return (x1-x)*(x1-x) + (y1-y)*(y1-y) <= r*r } `

## 4:

If you only care about relative distance you shouldn't use square root you can do something like:.

` rSquared = radius * radius #square the radius foreach x, y in Points do dX = (x - centerX) * (x - centerX) #delta X dY = (y - centerY) * (y - centerY) #delta Y if ( dX + dY <= rSquared ) then #Point is within Circle end end `

## 5:

Using the equation for a circle:.

We perform the test using this equation:.

If it works (the inequality is true), the point is inside of the circle.

Otherwise, it isn't..

`radius ** 2 = (x - centerX) ** 2 + (y - centerY) ** 2 `

We want to find if a point `(x, y)`

is inside of the circle. We perform the test using this equation:.

`radius ** 2 < (x - centerX) ** 2 + (y - centerY) ** 2 // (Or use <= if you want the circumference of the circle to be included as well) `

Simply substitute your values into that equation. If it works (the inequality is true), the point is inside of the circle.

Otherwise, it isn't..