Re: Point between 2 points
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Wed, 19 Apr 2006 14:19:27 GMT
<alexandre_paterson@xxxxxxxx> wrote in message news:1145419961.987979.208030@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Alex Hunsley wrote:alexandre_paterson@xxxxxxxx wrote:
> Genevieve wrote:
>> Hi,
>>
>> How would I find if a point(x, y) is between 2 points?
>> It could depend of x or y like point(50,100) is between (25,100) and
>> (150,100)
>> AND
>> point(50,100) is between (50,25) and (50,150).
>
> Hi,
>
> point C is between the segment defined by points A and B if
> the distance from A to C plus the distance from B to C is
> equal to the distance from A to C.
>
> This can be computed on a single (ugly) line or you can use
> Line2D's ptSegDist() method and check if you receive 0.0D
> as the result.
>
> Alex
Checking for 0.0D (or 0.0F) isn't always a practical solution, due to
floating point inaccuracies. Normally you should check that the result
is within a certain error range of the desired result, i.e. get the
distance and check that it is less than or equal to 0.000001 (for example).
you mean using a small positive quantity... An... An epsilon!
(lowercase epsilon).
:)
I'm fully aware of that ;)
I even have the old habit of calling the double holding the
epsilon EPS in my code. I guess I could use ' e ' if I wanted
to be fancy nowadays :)
There still exists cases where inaccuracy exists as you point
out, but the OP is unlikely to encounter it when working with
what looks like integer screen coordinates. And using an epsilon
only helps to define an "acceptable" error margin: for sufficiently
large (and small) values, there will still be cases where the answer
will be mathematically wrong.
If this is for graphics or games, what is usually happens is that we don't talk about lines at all, but rather "very thin" rectangles for act as lines. Or equivalently, we talk about lines with thickness. At that point, it becomes very precise what we meant when we say the point is "in" the line, and the appropriate epsilon value is more obvious.
- Oliver
.
- References:
- Point between 2 points
- From: Genevieve
- Re: Point between 2 points
- From: alexandre_paterson
- Re: Point between 2 points
- From: Alex Hunsley
- Re: Point between 2 points
- From: alexandre_paterson
- Point between 2 points
- Prev by Date: Re: Point between 2 points
- Next by Date: Re: GUI Tool in NetBeans
- Previous by thread: Re: Point between 2 points
- Next by thread: Re: Point between 2 points
- Index(es):
Relevant Pages
|