Convex hull

Hello, I have two vectors, x, and y:
x = [0.3333 0.5000 0.6667 0.7000]
x =
0.3333 0.5000 0.6667 0.7000
>> y = [0.6667 0.5000 0.3333 0.7000]
y =
0.6667 0.5000 0.3333 0.7000
>> convhull(x,y)
ans =
1
3
4
1
>> I know that (0.5 0.5) should theoretically be in the hull. If I try this, it works: x = single(x)
x =
0.3333 0.5000 0.6667 0.7000
>> y = single(y)
y =
0.6667 0.5000 0.3333 0.7000
>> x = double(x)
x =
0.3333 0.5000 0.6667 0.7000
>> y = double(y)
y =
0.6667 0.5000 0.3333 0.7000
>> convhull(x,y)
ans =
1
2
3
4
1
Now notice point 2 appears. So two questions: 1) Why does switching to single and coming back to double work? 2) Why does (0.5,0.5) not appear initially as part of the hull? Thank you, Raghu

Respuestas (1)

Jan
Jan el 10 de Mzo. de 2011

3 votos

The point (0.5, 0.5) is almost an element of the edge. Rounding to SINGLE and increasing the precision back to DOUBLE can move all points a little bit. Remember that 0.6667 is not 2*0.3333 and that floating point numbers in decimal notation do not have necessarily an exactly equal representation in binary notation, which are used for computations.
See also:

Categorías

Preguntada:

el 10 de Mzo. de 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by