3

I have this code:

coords = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0.5, 0.1}, {1.1, 
         0.5}, {0.5, 1.1}, {0.1, 0.5}, {0.6, 0.6}}};
nnodes = Flatten[coords, 1];
l1 = {{0, 0}, {0.5, 0.1}, {1, 0}};
l2 = {{1, 0}, {1.1, 0.5}, {1, 1}};
l3 = {{1, 1}, {0.5, 1.1}, {0, 1}};
l4 = {{0, 1}, {0.1, 0.5}, {0, 0}};
meshvis = Graphics[BezierCurve[{l1, l2, l3, l4}, SplineDegree -> 2]];
nodevis = Graphics[{Black, PointSize[Medium], Point[nnodes]}];
nodenumb = Graphics[{MapIndexed[Text[#2[[1]], #1, {2, 2}] &, nnodes],{Black,Point[nnodes]}}];
defel = Show[meshvis, nodevis, nodenumb]

Which generetes the following figure:

enter image description here

This result is not what i want. I need the curve passes through all points(except through point 9). Any suggestions on how to approach this?

Stratus
  • 2,942
  • 12
  • 24

1 Answers1

6

You could try the following using the fact that 3 points define a unique parabola. Must fit in the x and y directions separately.

coords = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0.5, 0.1}, {1.1, 
 0.5}, {0.5, 1.1}, {0.1, 0.5}, {0.6, 0.6}}};
xcurves = Fit[coords[[1, #]], {1, x, x^2}, x] & /@ {{1, 5, 2}, {4, 7, 3}}
ycurves=Fit[Reverse/@coords[[1,#]],{1,y,y^2},y]&/@{{1,8,4},{2,6,3}}
Show[Graphics[{PointSize[0.02],Point/@coords}],Plot[xcurves,{x,0,1},PlotStyle->Blue],ContourPlot[{x==First@ycurves,x==Last@ycurves},{x,0,1.2},{y,0,1},ContourStyle->Blue]]

XY Parabola fit

Feyre
  • 8,597
  • 2
  • 27
  • 46
John McGee
  • 411
  • 2
  • 4