Re: How can I determine if a point is a given distance from a second point?



On Mar 31, 2:24 pm, "Tom P." <padilla.he...@xxxxxxxxx> wrote:
I am writing a drawing program but I want to keep the scale down
(there could end up being several hundred objects on the screen).

I want to limit the points collected to a certain distance from other
points already collected, in other words, if you're drawing a line it
will only record points on the line every 6 pixels. How do I determine
how far away one point is from another? if they are restricted to
straight lines that's fine but as soon as they draw at an angle I'm
faced with determining how far away one point is from another in co-
ordinate space.

Any help would be appreciated.

Tom P.

You are not very clear in the description, what exactly you want to
do. If you need precise distance in 3D (or 2D) space because you are
writing CAD like vector based application then you need to use precise
phytagorean floating point based distance calculation. In order to
save time you can skip the square root and instead of distance limit
of 6.0 use it's square value 36.0 to eliminate points recorded "too
close" to the previous. The problem arises when your drafting program
allows for curves that can loop and intersect itself, because then the
points that are close geometrically might not neccesairly belong to
the subsequent recording and both should be recorded to preserve curve
shape. That can be achieved by comparing every recorded point only
with the very previous one accepted, which has extra benefit of also
being efficient and fast assuming subsequent points define just one
curve. If this is not your intention that you might need to compare
each recorded entry to every point previously accepted which will be
expensive. In such case I would rather divide the entire 2D working
space into cells of 6 x 6 pixels (in 3D case you would need 6 x 6 x 6
cell) and keep status of each cell in the array. If for example your
2D working space has 600 x 600 pixels size than you would need array
of 100 x 100 cells to record your points. If some newly recorded point
falls into the particular cell that is already occupied then it would
be rejected and obviously accepted otherwise. If the array approach is
too expensive in memory you can limit yourslef to comparing just delta
x, delta y (and delta z for 3D) between points (subsequent or
alldepending on your needs). If every absolute value of delta between
comapared points falls below 6 than the point is rejected or otherwise
accepted The downside of this approach is that it would keep 6 pixels
distance along x axis or along y axis, but the limit would be larger
along some angle to the primary coordinate system. In the extreme 45
degrees you would eliminate points that are less than 8.48 pixels
apart (2.48 pixels "too much" based on your criteria). This later
approach would be more suited for the drafting application that is
raster based where exact distance at an angle to the raster pixel
matrix has no good physical meaning since display pixes fall into the
integer rectangular grid. I guess one could use rounding functions to
simulate circle but that would probably lead to the expensive
algorithm without much gain in display quality.
.



Relevant Pages

  • Print resolution (was: Where are the BEST Point and Shoot Photos?)
    ... viewing conditions and at normal viewing distance of 22" needs only 156 ... PPI for excellent results, ... CRT high frequency response limits the contrast between adjacent pixels ... Measure your distance from the screen at this point. ...
    (rec.photo.digital)
  • Re: More on 720 vs 1080, plasma
    ... From the chart on viewing ... The sizes in the second chart seem very large to me, but if you want a home ... Most charts give you the distance where a normal eye can resolve the ... distance is to increase the distance somewhat so that the pixels blend ...
    (alt.tv.tech.hdtv)
  • Re: MMX speedup for Floyd Steinberg error diffusion
    ... The edges are handled by ignoring all pixels which do not have the ... neighbours, the simplest way I found was to keep my x and y loops ... Well Initially the code used the standard distance matching algorithm ... the wrong palate colour (not the nearest according to the ...
    (comp.lang.asm.x86)
  • Re: Where are the BEST Point and Shoot Photos ?
    ... viewing conditions and at normal viewing distance of 22" needs only 156 ... camera when viewed at a distance of two feet. ... You're looking at the details so much because your photography ... resolution, more clarity, more pixels, THEN someone will be able to see my ...
    (rec.photo.digital)
  • Re: Looking for info
    ... It goes to the local cell tower and gives you a dial tone then you dial ... of the long distance cell phone without long distance ... distance service charges. ...
    (alt.security.alarms)