Re: Distance problem
- To: mathgroup at smc.vnet.net
- Subject: [mg16355] Re: [mg16256] Distance problem
- From: BobHanlon at aol.com
- Date: Thu, 11 Mar 1999 02:16:35 -0500
- Sender: owner-wri-mathgroup at wolfram.com
>Mietta Lennes wrote:
>
> I need to draw a figure picturing the relative interdistances of a limited
> set of labeled points. The distance of each point to every other point is
> known. On the basis of this information, is there a way to draw a 2- or
> 3-dimensional "map" where each point's location (coordinates) corresponds
> to its distance to other points? On which terms is this possible?
>
> Is there a computer program that can at least approximate this?
>
> I am writing a paper in which this kind of figures would be most useful
> and enlightening... but I need the information fast. Please mail any
> possible answers straight to me.
>
Mietta,
The distance between two points is given by
dist[x_, y_] := Sqrt[Plus @@ ((x-y)^2)] /;
Length[x] == Length[y]
To be able to display the results, the points are assumed to be
two-dimensional
pts = Table[{Random[], Random[]}, {10}];
You need to define a metric, here I use the average distance of
a point from all of its neighbors
avgDist =((Plus @@ #)/(Length[pts]-1))& /@
Table[dist[pts[[k]], #]& /@ pts, {k, Length[pts]}];
Using the average distance as the z coordinate
ptsDist = Partition[Flatten[Transpose[{pts, avgDist}]], 3];
Needs["Graphics`Graphics3D`"];
Plotting the two-dimensional points
ListPlot[pts, PlotRange -> {{0, 1}, {0, 1}},
PlotStyle -> AbsolutePointSize[3]];
Using the average distance as the z coordinate
ScatterPlot3D[ptsDist, PlotRange -> {{0, 1}, {0, 1}, Automatic},
PlotStyle -> AbsolutePointSize[3]];
Ordering points by increasing average distance (z coordinate)
and joining the plot
ScatterPlot3D[Sort[ptsDist, #1[[3]] < #2[[3]]&],
PlotRange -> {{0, 1}, {0, 1}, Automatic},
PlotStyle -> {RGBColor[1, 0, 0], AbsoluteThickness[2]},
PlotJoined -> True,
ViewPoint -> {1.5, -2.4, 1.}];
You will need to play with the ViewPoint to get the best viewing
angle for a given set of points.
As expected, points near the center of the points have smaller
average distance than those out at the edges.
Bob Hanlon