3
$\begingroup$

I would like to plot a line in 3D with the following set of (x,y,z) data points:

zeroth={{0.198494, 1.0698, 0.}, {0.198494, 1.0698, 0.}, {0.322084, 0.942887, 
  0.}, {0.322084, 0.942887, 0.}, {0.57675, 0.374922, 0.}, {0.57675, 
  0.374922, 0.}, {0.185552, 1.08436, 0.0174533}, {0.21515, 
  1.04994, -0.0174533}, {0.294367, 0.969347, -0.0174533}, {0.34339, 
  0.92289, 0.0174533}, {0.572446, 0.382744, -0.0174533}, {0.580764, 
  0.366278, 0.0174533}, {0.17605, 1.0959, 0.0349066}, {0.361884, 
  0.905559, 0.0349066}, {0.568021, 0.390999, -0.0349066}, {0.584708, 
  0.358305, 0.0349066}, {0.167861, 1.10553, 0.0523599}, {0.378751, 
  0.888973, 0.0523599}, {0.563454, 0.398726, -0.0523599}, {0.588342, 
  0.34942, 0.0523599}, {0.160579, 1.11425, 0.0698132}, {0.394408, 
  0.873581, 0.0698132}, {0.558652, 0.406566, -0.0698132}, {0.59183, 
  0.341176, 0.0698132}, {0.154665, 1.12179, 0.0872665}, {0.408502, 
  0.859143, 0.0872665}, {0.553815, 0.414281, -0.0872665}, {0.595093, 
  0.332111, 0.0872665}, {0.148905, 1.12994, 0.10472}, {0.422286, 
  0.844652, 0.10472}, {0.548771, 0.421794, -0.10472}, {0.598436, 
  0.324043, 0.10472}, {0.143945, 1.13674, 0.122173}, {0.435713, 
  0.830522, 0.122173}, {0.543751, 0.429605, -0.122173}, {0.601712, 
  0.315436, 0.122173}, {0.13916, 1.14317, 0.139626}, {0.448665, 
  0.816578, 0.139626}, {0.538415, 0.436682, -0.139626}, {0.604995, 
  0.307611, 0.139626}, {0.134868, 1.14949, 0.15708}, {0.461357, 
  0.802559, 0.15708}, {0.533104, 0.444824, -0.15708}, {0.608272, 
  0.299628, 0.15708}, {0.129782, 1.15451, 0.174533}, {0.473408, 
  0.788929, 0.174533}, {0.527582, 0.45209, -0.174533}, {0.61164, 
  0.292204, 0.174533}, {0.126021, 1.16121, 0.191986}, {0.485063, 
  0.775353, 0.191986}, {0.522158, 0.460227, -0.191986}, {0.615157, 
  0.285094, 0.191986}, {0.122085, 1.16774, 0.20944}, {0.496837, 
  0.761577, 0.20944}, {0.516556, 0.467829, -0.20944}, {0.618775, 
  0.278227, 0.20944}, {0.119003, 1.17317, 0.226893}, {0.508827, 
  0.747717, 0.226893}, {0.510879, 0.475897, -0.226893}, {0.622811, 
  0.272617, 0.226893}, {0.116073, 1.17897, 0.244346}, {0.505164, 
  0.484005, -0.244346}, {0.520636, 0.733307, 0.244346}, {0.626954, 
  0.267086, 0.244346}, {0.113093, 1.18503, 0.261799}, {0.499224, 
  0.492086, -0.261799}, {0.532218, 0.719114, 0.261799}, {0.6313, 
  0.261968, 0.261799}, {0.111577, 1.19167, 0.279253}, {0.493298, 
  0.500625, -0.279253}, {0.543953, 0.704469, 0.279253}, {0.636088, 
  0.258389, 0.279253}, {0.108799, 1.1972, 0.296706}, {0.487396, 
  0.508923, -0.296706}, {0.555849, 0.689419, 0.296706}, {0.641129, 
  0.255432, 0.296706}, {0.106535, 1.2035, 0.314159}, {0.481012, 
  0.517715, -0.314159}, {0.568098, 0.674051, 0.314159}, {0.646641, 
  0.253596, 0.314159}, {0.104292, 1.20896, 0.331613}, {0.475234, 
  0.526562, -0.331613}, {0.580646, 0.657968, 0.331613}, {0.65242, 
  0.252806, 0.331613}, {0.102239, 1.21486, 0.349066}, {0.468873, 
  0.535884, -0.349066}, {0.593276, 0.640871, 0.349066}, {0.658571, 
  0.253369, 0.349066}, {0.0982709, 1.22702, 0.383972}, {0.456379, 
  0.554673, -0.383972}, {0.619857, 0.604587, 0.383972}, {0.672131, 
  0.259157, 0.383972}, {0.0965641, 1.23333, 0.401426}, {0.449861, 
  0.56449, -0.401426}, {0.63348, 0.584245, 0.401426}, {0.679381, 
  0.264944, 0.401426}, {0.0950336, 1.23899, 0.418879}, {0.44376, 
  0.574216, -0.418879}, {0.64757, 0.562168, 0.418879}, {0.686969, 
  0.27326, 0.418879}, {0.0935244, 1.24598, 0.436332}, {0.437062, 
  0.58483, -0.436332}, {0.661851, 0.53807, 0.436332}, {0.694583, 
  0.284399, 0.436332}, {0.0921628, 1.25235, 0.453786}, {0.430873, 
  0.594848, -0.453786}, {0.676327, 0.510554, 0.453786}, {0.702176, 
  0.299373, 0.453786}, {0.0909057, 1.25903, 0.471239}, {0.424158, 
  0.605928, -0.471239}, {0.690953, 0.478092, 0.471239}, {0.709389, 
  0.321384, 0.471239}, {0.0893533, 1.26508, 0.488692}, {0.41776, 
  0.61694, -0.488692}, {0.706706, 0.428366, 0.488692}, {0.714591, 
  0.362054, 0.488692}, {0.0882802, 1.27209, 0.506145}, {0.41175, 
  0.627661, -0.506145}, {0.0866466, 1.28613, 0.541052}, {0.398553, 
  0.651324, -0.541052}, {0.0853558, 1.30122, 0.575959}, {0.385974, 
  0.675517, -0.575959}, {0.990179, 0.477353, -0.575959}, {0.0843251, 
  1.31734, 0.610865}, {0.374344, 0.700272, -0.610865}, {0.989617, 
  0.481456, -0.610865}, {0.0837457, 1.334, 0.645772}, {0.36147, 
  0.726643, -0.645772}, {0.638353, 2.23413, 0.645772}, {0.721625, 
  1.67325, 0.645772}, {0.98831, 0.487965, -0.645772}, {0.083432, 
  1.35147, 0.680678}, {0.351011, 0.753154, -0.680678}, {0.614957, 
  2.36198, 0.680678}, {0.738558, 1.56717, 0.680678}, {0.987528, 
  0.496026, -0.680678}, {0.0846713, 1.41083, 0.785398}, {0.32184, 
  0.837719, -0.785398}, {0.55034, 2.62464, 0.785398}, {0.775262, 
  1.36775, 0.785398}, {0.982083, 0.524919, -0.785398}, {0.0886045, 
  1.4721, 0.872665}, {0.300202, 0.91366, -0.872665}, {0.492325, 
  2.76435, 0.872665}, {0.801811, 1.24334, 0.872665}, {0.978066, 
  0.553219, -0.872665}, {0.0959591, 1.54927, 0.959931}, {0.285895, 
  0.991105, -0.959931}, {0.422616, 2.80221, 0.959931}, {0.826049, 
  1.13403, 0.959931}, {0.973523, 0.586711, -0.959931}, {0.0979165, 
  1.56701, 0.977384}, {0.283131, 1.00706, -0.977384}, {0.406624, 
  2.79012, 0.977384}, {0.830947, 1.11328, 0.977384}, {0.973158, 
  0.593456, -0.977384}, {0.100044, 1.58604, 0.994838}, {0.280764, 
  1.02302, -0.994838}, {0.389799, 2.76998, 0.994838}, {0.835528, 
  1.09255, 0.994838}, {0.972037, 0.600484, -0.994838}, {0.102697, 
  1.60734, 1.01229}, {0.278703, 1.03898, -1.01229}, {0.372536, 
  2.74151, 1.01229}, {0.840056, 1.07216, 1.01229}, {0.971291, 
  0.607065, -1.01229}, {0.105605, 1.62932, 1.02974}, {0.277003, 
  1.05492, -1.02974}, {0.354966, 2.70486, 1.02974}, {0.84457, 1.0528, 
  1.02974}, {0.970776, 0.613843, -1.02974}, {0.108686, 1.6531, 
  1.0472}, {0.275683, 1.07085, -1.0472}, {0.337019, 2.65854, 
  1.0472}, {0.849307, 1.03206, 1.0472}, {0.970224, 
  0.620753, -1.0472}, {0.112466, 1.67917, 1.06465}, {0.274745, 
  1.08676, -1.06465}, {0.318697, 2.60254, 1.06465}, {0.853779, 
  1.01239, 1.06465}, {0.9696, 0.627347, -1.06465}, {0.116736, 1.70841,
   1.0821}, {0.274132, 1.10263, -1.0821}, {0.299959, 2.54008, 
  1.0821}, {0.85664, 1.00265, 1.0821}, {0.968657, 
  0.635535, -1.0821}, {0.12178, 1.74126, 1.09956}, {0.27386, 
  1.11846, -1.09956}, {0.281863, 2.47482, 1.09956}, {0.862555, 
  0.974361, 1.09956}, {0.968051, 0.643422, -1.09956}, {0.127955, 
  1.77924, 1.11701}, {0.2626, 2.39964, 1.11701}, {0.273813, 
  1.13432, -1.11701}, {0.866909, 0.954428, 1.11701}, {0.967556, 
  0.649815, -1.11701}, {0.136169, 1.82681, 1.13446}, {0.242183, 
  2.31712, 1.13446}, {0.271801, 1.1507, -1.13446}, {0.871239, 
  0.934992, 1.13446}, {0.966909, 0.65698, -1.13446}, {0.269036, 
  1.18347, -1.16937}, {0.879684, 0.89653, 1.16937}, {0.965879, 
  0.67101, -1.16937}, {0.267177, 1.21624, -1.20428}, {0.887911, 
  0.858914, 1.20428}, {0.965201, 0.684694, -1.20428}, {0.26691, 
  1.2326, -1.22173}, {0.891907, 0.840493, 1.22173}, {0.964468, 
  0.692467, -1.22173}, {0.276434, 1.39499, -1.39626}, {0.928396, 
  0.670141, 1.39626}, {0.960476, 0.764928, -1.39626}, {0.296021, 
  1.55679, -1.5708}, {0.957321, 0.535832, 1.5708}, {0.95374, 
  0.862105, -1.5708}, {0.34458, 1.71073, -1.74533}, {0.936774, 
  1.01638, -1.74533}, {0.979354, 0.440014, 1.74533}, {0.350642, 
  1.72532, -1.76278}, {0.93396, 1.03733, -1.76278}, {0.980757, 
  0.434975, 1.76278}, {0.357762, 1.73963, -1.78024}, {0.930574, 
  1.05985, -1.78024}, {0.98174, 0.431363, 1.78024}, {0.366583, 
  1.75341, -1.79769}, {0.927179, 1.08387, -1.79769}, {0.982802, 
  0.426881, 1.79769}, {0.37735, 1.76655, -1.81514}, {0.92329, 
  1.10887, -1.81514}, {0.984009, 0.422373, 1.81514}, {0.389842, 
  1.77887, -1.8326}, {0.918766, 1.13617, -1.8326}, {0.98526, 0.418057,
   1.8326}, {0.402315, 1.79078, -1.85005}, {0.913131, 
  1.16773, -1.85005}, {0.986116, 0.418629, 1.85005}, {0.418305, 
  1.80127, -1.8675}, {0.907431, 1.19908, -1.8675}, {0.987491, 
  0.415291, 1.8675}, {0.435393, 1.81067, -1.88496}, {0.9006, 
  1.23281, -1.88496}, {0.988555, 0.412967, 1.88496}, {0.456828, 
  1.81772, -1.90241}, {0.893493, 1.26884, -1.90241}, {0.482352, 
  1.82181, -1.91986}, {0.884626, 1.30895, -1.91986}, {0.511384, 
  1.82261, -1.93732}, {0.87373, 1.3539, -1.93732}, {0.547423, 
  1.8171, -1.95477}, {0.859477, 1.4063, -1.95477}, {0.592721, 
  1.80156, -1.97222}, {0.842038, 1.46298, -1.97222}, {0.651874, 
  1.76664, -1.98968}, {0.813639, 1.53909, -1.98968}}

Here is a visualization of the points:

ListPointPlot3D[zeroth,PlotRange->All,PlotStyle->Black,Boxed->False]

enter image description here

When I try to plot it as a single line I get this nightmare:

Graphics3D[{Red,Thick,Line[zeroth]}]

enter image description here

I don't know if there is a way to use the FindShortestTour with this 3D data. I have always used it for 2D data. The only approximate example that I could find in the documentation was example/FindTheShortestTourAroundTheWorld. But that case I think that is less general because there they deal with point in 3D but at the same distance to the origin, which does not apply here.

$\endgroup$
9
  • $\begingroup$ looks like your points are in a wrong order. When you plot just points order doesn't matter. When you plot lines the order determines which points are connected together. Even your first 20 points are all over the place Graphics3D[{Red, Thick, Line[zeroth[[1 ;; 20]]]}, Axes -> True] $\endgroup$
    – BlacKow
    Jun 12, 2015 at 20:01
  • $\begingroup$ Oh.. I see now, yes, it seems to work… Graphics3D[{Red, Thick, Line[zeroth[[FindShortestTour[zeroth][[2]]]]]}] $\endgroup$
    – BlacKow
    Jun 12, 2015 at 20:06
  • $\begingroup$ It is the line of zeros of a function of three variables, and I got those points ordered in z. I think that the answer you gave would do the job if I only could choose the ending points. Because it looks like it is connecting some points that I guess that are not connected. $\endgroup$
    – Francisco
    Jun 12, 2015 at 20:11
  • $\begingroup$ My guess is that it is a single open line, i.e. with two extrema. $\endgroup$
    – Francisco
    Jun 12, 2015 at 20:16
  • 1
    $\begingroup$ It is a complex function which depends on three variables, I search the points where the real and imaginary parts of this function vanish in each [x,y] plane for z fix, and I move through the z axis performing this operation. There can be 0, 1, 2 or even 3 zeros in each [x,y] plane. But they all seem to be connected in [x,y,z] $\endgroup$
    – Francisco
    Jun 12, 2015 at 20:27

1 Answer 1

7
$\begingroup$

We can turn your data into a weighted adjacency graph by using Outer and, well, WeightedAdjacencyGraph:

adjgraph = WeightedAdjacencyGraph[Outer[EuclideanDistance, zeroth, zeroth, 1, 1]];
tour = FindShortestTour[adjgraph];
Show[ListPointPlot3D[zeroth, PlotRange -> All, PlotStyle -> Black, Boxed -> False], 
  Graphics3D[{Darker[Red], Line[zeroth[[tour[[2]]]]]}]]

connect the dots, la la la la

Amusingly, it takes longer for Mathematica to actually construct the adjacency matrix on my computer then it does to actually find the tour (0.35 sec vs. 0.055 sec, respectively.)

$\endgroup$
8
  • $\begingroup$ I wonder how the endpoints could be identified. In this particular case the "discontinous" derivatives could help $\endgroup$ Jun 13, 2015 at 4:03
  • $\begingroup$ In this case, a quick & dirty way would be to assume that the two consecutive points with the greatest distance between them are the endpoints. I like the idea of looking at the angles too. $\endgroup$ Jun 13, 2015 at 12:20
  • $\begingroup$ Thank you very much for your answer, it solved my problem. I think that a three point derivative criterion would be enough because the line is smooth enough except at the endpoints. There is also a restriction on the curve, it cannot go further than x=1. Is there a way to force the program not to connect two specific points? $\endgroup$
    – Francisco
    Jun 13, 2015 at 14:45
  • $\begingroup$ If you don't want the resulting tour to contain a link between two particular points $i$ and $j$, set adjmatrix[[i,j]] = Infinity. FindShortestTour will still try to find a closed path containing all the points, though; it just won't connect $i$ to $j$ in the tour. I don't think there's an easy way to force it to create an "open" tour. $\endgroup$ Jun 13, 2015 at 19:01
  • $\begingroup$ Hello again. Michael, it seems like something is missing in the code you posted. Could you check it, please? I am not getting the same plot as you, and I can not find the adjmatrix you mention also. $\endgroup$
    – Francisco
    Jun 14, 2015 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.