Skip to main content

interpolation - Make an offset curve (parallel curve)


I have a polynomial curve that I got through interpolation.


pts1 = {{0, 0}, {12, 27}, {31, 52}, {58, 73}, {81, 85}};
y1 = pts1[[#, 1]] & /@ Range[Length[pts1]];
eq1 = Fit[pts1, {1, x, x^2, x^3, x^4}, x]//Chop;



$-2.74861*10^{-6}x⁴+0.00059554 x³-0.0516843 x²+2.7892 x$



eq1 /. x -> y1;


${0,27,52,73,85}$



pl1 = Plot[eq1, {x, Min[y1], Max[y1]}, Epilog -> {Blue, PointSize[0.02], Point[pts1]}, PlotRange -> {{-10, 100}, {-10, 100}}, AspectRatio -> 1, PlotStyle -> {Orange, Thick}]

I want to make another offset curve in 10 units. But I do not know how to proceed within Mathematica.



enter image description here


I made an offset through another software using multiple circles with a 10-unit radius to get the points I need.


enter image description here


Anyway, what would be the appropriate command to get these points?



Answer



This involves an algebraic curve so it can be done in closed form (one approach already shown does this, in the parametric form). We'll do the interpolation below at high precision in order to make some later computations more reliable.


pts1 = {{0, 0}, {12, 27}, {31, 52}, {58, 73}, {81, 85}};
f[x_] = Fit[N[pts1, 200], {1, x, x^2, x^3, x^4}, x];
N[f[x]]


(* Out[1252]= 0. + 2.78920381052 x - 0.0516843269209 x^2 +
0.000595539716825 x^3 - 2.74861498447*10^-6 x^4 *)

Here we find the parametric form of the (lower) offset curve).


offset[x_] = 
With[{deriv = D[{x, f[x]}, x]},
{grad = {-deriv[[2]], deriv[[1]]}},
{x, f[x]} - grad/Sqrt[grad.grad]*10];

We check the plot.



ParametricPlot[{{t, f[t]}, offset[t]}, {t, 0, 80}]

plot


We can also implicitize. This part required the high precision interpolation. We could use Rationalize but that can get into round-off and cancellation error problems in plotting, since coefficients appear at very different scales.


imp = First[
GroebnerBasis[Together[{x, y} - offset[t]], {x, y}, t,
MonomialOrder -> EliminationOrder]];
imp // N

(* Out[1260]= -6.73373194281*10^25 + 5.56558925951*10^24 x +

3.6738758353*10^23 x^2 - 4.34415318895*10^22 x^3 +
1.93344441642*10^21 x^4 - 5.36588154643*10^19 x^5 +
1.06609597248*10^18 x^6 - 1.60542472424*10^16 x^7 +
1.88490826277*10^14 x^8 - 1.74235671779*10^12 x^9 +
1.26230731848*10^10 x^10 - 7.01480518001*10^7 x^11 +
284576.519771 x^12 - 758.341572269 x^13 + 1. x^14 +
3.72787534059*10^24 y - 6.8504825964*10^23 x y +
9.94066556163*10^21 x^2 y + 7.41868236137*10^20 x^3 y -
4.34299189813*10^19 x^4 y + 1.19168781004*10^18 x^5 y -
2.1498342949*10^16 x^6 y + 2.77290008879*10^14 x^7 y -

2.63253515622*10^12 x^8 y + 1.82904347319*10^10 x^9 y -
8.95087000739*10^7 x^10 y + 280923.407204 x^11 y -
426.500272743 x^12 y - 3.17385078171*10^22 y^2 +
2.18287264042*10^22 x y^2 - 3.93259394774*10^20 x^2 y^2 -
1.00071010929*10^19 x^3 y^2 + 6.86935186234*10^17 x^4 y^2 -
1.75325222649*10^16 x^5 y^2 + 2.83739730618*10^14 x^6 y^2 -
3.21684582573*10^12 x^7 y^2 + 2.65009867828*10^10 x^8 y^2 -
1.59027982886*10^8 x^9 y^2 + 677296.69588 x^10 y^2 -
1950.02118583 x^11 y^2 + 3. x^12 y^2 - 1.48945282252*10^21 y^3 -
4.62703214764*10^20 x y^3 + 8.5373151706*10^18 x^2 y^3 +

6.50159149141*10^16 x^3 y^3 - 6.85046668404*10^15 x^4 y^3 +
1.58285949288*10^14 x^5 y^3 - 2.17546347848*10^12 x^6 y^3 +
1.98184395157*10^10 x^7 y^3 - 1.20720722952*10^8 x^8 y^3 +
465742.200007 x^9 y^3 - 853.000545485 x^10 y^3 +
6.2893710958*10^19 y^4 + 6.33039722844*10^18 x y^4 -
1.1302847025*10^17 x^2 y^4 + 4.83188192567*10^13 x^3 y^4 +
4.60017785742*10^13 x^4 y^4 - 9.9826564209*10^11 x^5 y^4 +
1.20048427437*10^10 x^6 y^4 - 9.37112169389*10^7 x^7 y^4 +
476873.182752 x^8 y^4 - 1625.01765486 x^9 y^4 + 3. x^10 y^4 -
1.09303426085*10^18 y^5 - 5.50342304678*10^16 x y^5 +

9.17636707233*10^14 x^2 y^5 - 4.3681823605*10^12 x^3 y^5 -
1.76328081245*10^11 x^4 y^5 + 3.57598551957*10^9 x^5 y^5 -
3.37083626949*10^7 x^6 y^5 + 184818.792803 x^7 y^5 -
426.500272743 x^8 y^5 + 1.03689348135*10^16 y^6 +
2.95870424611*10^14 x y^6 - 4.66457552293*10^12 x^2 y^6 +
3.02885768057*10^10 x^3 y^6 + 4.65196245499*10^8 x^4 y^6 -
1.00479219318*10^7 x^5 y^6 + 84153.0066438 x^6 y^6 -
433.338041296 x^7 y^6 + 1. x^8 y^6 - 5.50780682701*10^13 y^7 -
7.85681314181*10^11 x y^7 + 1.41189443972*10^10 x^2 y^7 -
1.57656872186*10^8 x^3 y^7 + 727639.19694 x^4 y^7 +

1.32364700231*10^11 y^8 *)

We can check the zero contour.


ContourPlot[imp == 0, {x, 0, 60}, {y, 0, 80}]

plot


One will notice we got both upper and lower offsets. This is due to the fact that GroebnerBasis internals will make polynomial relations out of radicals, in effect losing information about sign on square roots.


Comments

Popular posts from this blog

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

calculus and analysis - Integral of the Sinc product

Let us consider the following integral $$ B_n = \int_0^\infty \prod_{k=1,3,5,\dots}^n\frac{\sin (x/k)}{x/k}dx $$ By definition, Sinc[x] == Sin[x]/x , therefore B[n_?OddQ] := Integrate[Product[Sinc[x/k], {k, 1, n, 2}], {x, 0, Infinity}] B /@ Range[1, 13, 2] {Pi/2, Pi/2, Pi/2, Pi/2, Pi/2, Pi/2, Pi/2} OK, everything is fine. But... B[15] 467807924713440738696537864469 Pi/935615849440640907310521750000 What's going on? Answer As Eckhard wrote in comments B[n] is the n-th Borwein integral . (The letter B was not accidental :) ) This funny properties of Borwein integrals is related to the Fourier transform of Sinc function FourierTransform[Sinc[x], x, k] 1/2 Sqrt[Pi/2] (Sign[1 - k] + Sign[1 + k]) Plot[%, {k, -2, 2}, Filling -> 0] which is the box function. The result is $\pi/2$ while the sum $$ 1/3+1/5+\dots+1/n $$ B_n = \frac{\pi}{2} - \pi \bigg(\sum_{k=3,5,\ldots}^n\frac{1}{k} -1\biggr)^\frac{n-1}{2}\prod_{k=3,5,\dots}^n\frac{k}{k-1}. $$ For $n=15$ it is equal to $$ \frac{46780...

list manipulation - Selecting multiple columns from a matrix?

Sample data: data = { {{2013, 1, 1}, 24.13, 167.67, 231.82}, {{2013, 1, 2}, 32.15, 170.92, 225.99}, {{2013, 1, 3}, 35.43, 172.68, 221.67}, {{2013, 1, 4}, 36.73, 173.05, 218.32}, {{2013, 1, 5}, 58.19, 165.96, 197.05}, {{2013, 1, 6}, 69.99, 163.50, 187.52}, {{2013, 1, 7}, 71.37, 154.21, 175.58}, {{2013, 1, 8}, 72.51, 149.66, 163.25}}; I want a DateListPlot with three graphs, so for a matrix formed by columns 1 and 2, one for columns 1 and 3, and 1 for columns 1 and 4. At the moment I'm using this code: data2 = Transpose[{data[[All, 1]], data[[All, 2]]}]; data3 = Transpose[{data[[All, 1]], data[[All, 3]]}]; data4 = Transpose[{data[[All, 1]], data[[All, 4]]}]; DateListPlot[{data2, data3, data4}, Joined -> True, Filling -> {3 -> {1}}] but I have a hunch that this can be done more efficiently. I don't like the Transpose s in particular. Any ideas? edit (for extra credit) What if I need to multiply the second column by 2, which in my solution is simp...