Re: Point between 2 points




<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

.



Relevant Pages

  • Re: Point between 2 points
    ... the distance from A to C plus the distance from B to C is ... (lowercase epsilon). ... floating-points arithmetics at all... ... post represented using some funky uncommon representation? ...
    (comp.lang.java.programmer)
  • Re: Accumulation points in metric space
    ... (i.e. there exists epsilon> 0 such that the distance ... subset is at least epsilon). ... If is a non-separable metric space, then ... non-separability of X, ...
    (sci.math)
  • Re: Accumulation points in metric space
    ... (i.e. there exists epsilon> 0 such that the distance ... subset is at least epsilon). ... a countable subset B_k of X such that the distance ... follows from the non-separability of X that X is ...
    (sci.math)
  • Re: [Dynamical Systems] Convergence to a fixed point
    ... >> stable manifold at a distance Ofrom x_0 to reach a distance ... that have absolute value <= 1, and r the maximum of the absolute ... sufficiently small epsilon. ...
    (sci.math)
  • Re: Point between 2 points
    ... the distance from A to C plus the distance from B to C is ... 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. ...
    (comp.lang.java.programmer)