0

I'm having a problem to plot a finite element solution. I have one array of orinal coordinates and an array with the new coordinates that I want to compare to the original array. The problem occurs when I try to use the ListPlot function. The ListPlot connect the wrong points. Here is the code:

allcoords = {{{0, 0}, {2, 0}, {2, 2}, {0, 2}}, {{2, 0}, {4, 0}, {4, 
     2}, {2, 2}}, {{4, 0}, {6, 0}, {6, 2}, {4, 2}}, {{6, 0}, {8, 
     0}, {8, 2}, {6, 2}}, {{0, 2}, {2, 2}, {2, 4}, {0, 4}}, {{2, 
     2}, {4, 2}, {4, 4}, {2, 4}}, {{4, 2}, {6, 2}, {6, 4}, {4, 
     4}}, {{6, 2}, {8, 2}, {8, 4}, {6, 4}}};
tabdeformed = {{0.1298087, 0.}, {2.11861, 0.`}, {4.09145241, 
    0.`}, {6.04989819195069`, 0.`}, {8.`, 0.`}, {8.`, 
    2.1329644641693166`}, {6.042519693730256`, 
    2.122638305596309`}, {4.078337372835341`, 
    2.0936720451127013`}, {2.101748416923281`, 
    2.0528629576754973`}, {0.11109027800216474`, 
    2.010820010989869`}, {8.`, 
    4.262007609299412`}, {6.016203961015385`, 
    4.241797525456124`}, {4.03110886320685`, 
    4.185184098398641`}, {2.04359292365999`, 
    4.103056727380703`}, {0.05011706001719006`, 4.018270354896997`}};
undefplot = 
  ListLinePlot[allcoords, AspectRatio -> Automatic, 
   PlotMarkers -> Automatic, Joined -> True];
defplot = 
  ListLinePlot[tabdeformed, AspectRatio -> Automatic, 
   PlotMarkers -> {Automatic, 12}, PlotStyle -> {Thick, Red, Dashed}];
Show[defplot, undefplot]
corey979
  • 23,947
  • 7
  • 58
  • 101
Stratus
  • 2,942
  • 12
  • 24

1 Answers1

1

Is this what you want?

nf = Nearest[tabdeformed]

tabdeformed2 = 
 ArrayReshape[#, Dimensions@allcoords] & @
  Flatten[nf @ Flatten[allcoords, 1], 1]

undefplot = 
  ListLinePlot[allcoords, AspectRatio -> Automatic, 
   PlotMarkers -> Automatic, Joined -> True];
defplot = 
  ListLinePlot[tabdeformed2, AspectRatio -> Automatic, 
   PlotMarkers -> {Automatic, 12}, 
   PlotStyle -> {Thick, Red, Dashed}];
Show[defplot, undefplot]

enter image description here

corey979
  • 23,947
  • 7
  • 58
  • 101