# Distance between 2 flat molecules

GROUPS:
 A Y 1 Vote Hi, do you have any idea how to measure the distance between the two planes? I am a new user with Mathematica and your help will be greatly appreciated. data1 = {{5.086735, -2.640504,     4.650624}, {6.227440, -2.477485, 3.843544}, {6.160519, -1.731605,     2.649288}, {4.941969, -1.164990, 2.267181}, {3.799611, -1.315889,     3.093711}, {3.864651, -2.054553, 4.284675}, {4.609149, -0.320793,     1.036262}, {3.147213, 0.034489, 1.303689}, {2.295200, 0.817536,     0.531891}, {0.950277, 1.010999, 0.934789}, {0.504240, 0.379798,     2.123730}, {1.354565, -0.416580, 2.898054}, {2.686409, -0.582108,     2.489055}, {0.024258, 1.821306, 0.114273}, {-1.353392, 1.513264,     0.069868}, {0.471982, 2.897945, -0.687157}, {-2.233955,    2.208380, -0.751826}, {-0.408676,    3.621409, -1.497147}, {-1.775026,    3.272191, -1.550693}, {-2.675546, 3.957425, -2.411557}};In[9]:= Plane1 = Fit[data1, {1, x, y}, {x, y}]Out[9]= 2.18037 - 0.200355 x - 1.20793 ydata2 = {{0.989404, -2.326574, -0.675663}, {0.466929, \-2.898174, 0.507492}, {-0.913869, -2.780568,    0.804534}, {-1.736679, -2.093564, -0.078413}, {-1.209589, \-1.521258, -1.260581}, {0.155306, -1.637212, -1.561214},   {-3.234276, -1.809443,    0.054719}, {-3.478451, -0.951209, -1.195212}, {-4.647861, \-0.326679, -1.645893}, {-4.618728, 0.428750, -2.833379}, {-3.433297,    0.549231, -3.579976}, {-2.261558, -0.087363, -3.148840}, \{-2.289342, -0.827551, -1.957816}, {1.326341, -3.595313,    1.453222}, {3.114413, -4.428375, 2.270776}, {2.668207, -3.758639 ,     1.167271}, {1.006758, -4.128596,    2.609730}, {2.180810, -4.675522, 3.140752}};In[16]= Plane2 = Fit[data2, {1, x, y}, {x, y}]Out[16]= -4.19445 - 0.401548 x - 1.7137 yShow[ListPlot3D[data1, PlotStyle -> Red], ListPlot3D[data2, PlotStyle -> Green], Plot3D[{Plane1, Plane2}, {x, -7, 7}, {y, -7, 7}]]
4 years ago
13 Replies
 Hello, Sarah, welcome to the Wolfram Community! Please take a few minutes to read this tutorial about correct posting – especially of Mathematica code:How to type up a post: editor tutorial & general tipsIf you will not follow the tutorial, other members of community may not be able to test your code. To edit your post – click “Edit” in the lower right corner of your post.
4 years ago
 Vitaliy Kaurov 2 Votes Please pay attention to how code is posted on this site and what Moderation Team recommended to you.I got your visualization working, but your planes are NOT parallel. So how (where) do you suggest to measure distance between them? pln1[x_, y_] = Fit[dataTPAF1, {1, x, y}, {x, y}]; pln2[x_, y_] = Fit[dataOXF1, {1, x, y}, {x, y}];   Show[   ListPointPlot3D[{dataTPAF1, dataOXF1},       PlotStyle -> {Directive[PointSize[Large], Red], Directive[PointSize[Large], Green]}],    Plot3D[{pln1[x, y], pln2[x, y]}, {x, -7, 7}, {y, -7, 7},       PlotStyle -> Opacity[.3], MeshStyle -> Opacity[.3]], SphericalRegion -> True]
4 years ago
 Dear Sir I use this formula and getting the distance from nanotube to Oligo(Polymer) center to center.1) can you help me to find the angle between this planes? 2) and how fit data workspln1[x, y] = Fit[dataTPAF1, {1, x, y}, {x, y}]; pln2[x, y] = Fit[dataOXF1, {1, x, y}, {x, y}]; Attachments:
3 years ago
 Thanks Vitaliy Kaurov for your help! You're right the planes are not parallel! Maybe we can measure the distance between the planes by taking the closest and the farthest distances and divide by two? Do you have any idea how to do that using Mathematica?
4 years ago
 Your planes will intersect. Closest and furthest distances between them are 0 and infinity respectively. But this is not really what you want.My guess is you want a measure of how far apart the fits are. This involves a measurement in your parameter space. One plausible way to proceed is as below.Say the plane equations are a_j x + b_j y + c_j z + d_j == 0 for j=1,2. For a sensible measurement you could normalize each plane equation so that sum of squares of coefficients is 1. That is, divide (a_j,b_j,c_j,d_j) by sqrt(a^j^2+...+d_j^2). You now have two normalized vectors in parametrization space. You can take the distance between them.
4 years ago
 Thanks Daniel,I tried to normalize the plane equations using the normalize function in Mathematica and then get the distance between the planes, but it didn't give me anything (Im not sure where the problem was).   Can you give me an idea how to do this with Mathematica, or is this the wrong apporach?
4 years ago
 Normalize the coefficient vectors. If the results are two vectors c1 and c2, next take Norm[c1-c2].I'm not sure if this answers your question. If not, it would be best if you posted the code you tried.
4 years ago
 I am not sure if I understood you right because I still don't know how to get the distance, but here's what I meant when I tried to normalize each plane equation:In[1]:= pln1 = Normalize[a*x1 + b*y1 + c*z1]Out[1]= (a x1 + b y1 + c z1)/Norm[a x1 + b y1 + c z1]In[2]:= pln2 = Normalize[a*x2 + b*y2 + c*z2]Out[2]= (a x2 + b y2 + c z2)/Norm[a x2 + b y2 + c z2]Also how can I include my data in the distance equetion ?Sqrt[a (x1 - x2)^2 + b (y1 - y2)^2 + c (z1 - z2)^2]
4 years ago
 Daniel Lichtblau 1 Vote To gauge distances will need to work with coefficient vectors, not equations.It would be very helpful if you gave background information on the full problem you are trying to solve. At this point I cannot say what would be a good way to assess distance since I'm not sure what we want distances of. Maybe you want to force the planes to be parallel (a simultaneous fit keeping x and y coefficients equal)? Hard to say without knowing something more about the actual problem at hand.
4 years ago
 The main problem is finding the distance between two molecules. In my first post above I included their data that represent their xyz coordinates. After fitting them into two planes, we need to measure the distance between these two planes. I don't want to force the planes to be parallel...I am wondering now if I want to get the distance between their closest and furthest and divide by two, Can I choose that from the graph? Cause it's hard to find them from just looking at the data! If you want to give me any other advice ease go ahead please!