distance

Purpose

Compute the distance between the given point/polyhedron and this polyhedron.

Syntax

dist = P.distance(x)
ret = P.distance(S)
dist = distance(P, x)
ret = distance(P, S)

Description

Compute the distance between the polyhedron P and the point x or the polyhedron S.
  1. By providing real vector ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance1.png, the distance between ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance2.png and ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance3.png is computed by solving the optimization problem

    ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance18.png

    and the distance is returned as real number.
  2. If polyhedron ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance4.png is specified as the argument, the distance between ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance5.png and ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance6.png is computed by solving the following optimization problem

    ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance19.png

    where the results of the optimization are returned in a struct format.

Input Arguments

P

Polyhedron in any format

Class: Polyhedron

x

Vector of size P.Dim

Class: double vector

S

Polyhedron with the same dimension as P.

Class: Polyhedron

Output Arguments

dist

Distance between the point ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance7.png and the Polyhedron ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance8.png

Class: double

ret

Optimal solution or [] if ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance9.png is empty.

Class: struct

ret.exitflag

Integer value informing about the termination status of the optimization.

Class: double

ret.dist

Distance from ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance10.png to the set ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance11.png

Class: double

ret.x

Point ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance12.png in ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance13.png closest to ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance14.png.

Class: double

ret.y

Point ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance15.png in ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance16.png closest to ../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance17.png.

Class: double

Example(s)

Example 1

Create a polytope:
P = ExamplePoly.poly3d_sin;
Choose a point and compute the distance:
y = [2;2];

d = P.distance(y);
Plot the result
P.plot; hold on; pplot(y','or');
      axis square; th=linspace(0,2*pi,100)';
      pplot(d.dist*[sin(th) cos(th)]+repmat(y',100,1),'k');

../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance_img_1.png

Example 2

Create two polyhedra:
P = ExamplePoly.poly3d_sin('d',3);

[U,s]=svd(randn(3)); 

S = ExamplePoly.poly3d_sin.affineMap(U(:,1:2)) + [2;2;2];
Compute the distance:
ret = distance(P,S);
Plot the result
plot([P S]); hold on; pplot([ret.x';ret.y'],'ok-'); axis square;

../../../../../../fig/mpt/modules/geometry/sets/@Polyhedron/distance_img_2.png

See Also

minvrep


© 2010-2013 Colin Neil Jones: EPF Lausanne, colin.jones@epfl.ch