# Add missing points in a 2D line

**URL:** <https://discourse.julialang.org/t/add-missing-points-in-a-2d-line/94211>\
**Category:** General Usage\
**Tags:** question, interpolations, splines\
**Created:** [February 7, 2023, 1:59pm UTC](https://discourse.julialang.org/t/add-missing-points-in-a-2d-line/94211 "2023-02-07T13:59:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benjamin\_Steinvorth](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@Benjamin\_Steinvorth](https://discourse.julialang.org/u/Benjamin_Steinvorth)\
**Post date:** [February 7, 2023, 1:59pm UTC](https://discourse.julialang.org/t/add-missing-points-in-a-2d-line/94211/1 "2023-02-07T13:59:59Z")

</div>

have some 2D data in Julia representing a circular feature with some “holes” in it. I like to interpolate these holes by finding points fitting on a curve representing the shape of the feature.

Using Julia’s `PlotlyJS` library I was able to find a nice `spline` interpolation curve for the points visually. However, I am not able to “access” that interpolation to calculate the actual points required. Any (alternative?) idea on how to get that?

Here is a working example:

```julia
using PlotlyJS

someData = [
    3.47336 -0.471233;
    3.53109 0.335963;
    3.46748 1.10433;
    3.13369 1.87227;
    2.33268 2.51022;
    1.21804 3.07551;
    0.211065 3.3075;
    -0.768256 3.18599;
    -1.72856 2.87655;
    -2.55477 2.58726;
    -3.28657 1.99779;
    -3.63637 1.31502;
    -3.56652 -0.462201;
    -2.96175 -0.956073;
    -2.0519 -0.870708;
    -1.07193 -0.837913;
    -0.156219 -0.972855;
    0.594719 -1.4576;
    1.27607 -1.9387;
    2.08427 -2.17288;
    3.47336 -0.471233
]
  
  
plot([
    scatter(
        x=someData[:,1], y=someData[:,2], type="scatter", mode="markers", name="Some data",
        marker=attr(size=8, color="orange", opacity=1)
    ), 
    scatter(
        x=someData[:,1], y=someData[:,2], type="scatter", mode="lines", name="Plotly spline",
        line=attr(color="green", width=2, shape="spline")
    ),

    ], Layout(scene=attr(aspectmode="data"), showlegend=true)
)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/f/2f2ecaa453125791fa3f391224ada01be6b7b6a8.png)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 7, 2023, 2:07pm UTC](https://discourse.julialang.org/t/add-missing-points-in-a-2d-line/94211/2 "2023-02-07T14:07:45Z")

</div>

You can use parametric splines. See some examples [in this other thread](https://discourse.julialang.org/t/simple-interpolation/55320).

---

<div class="post-metadata">

**Author:** ![Benjamin\_Steinvorth](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@Benjamin\_Steinvorth](https://discourse.julialang.org/u/Benjamin_Steinvorth)\
**Post date:** [February 7, 2023, 2:13pm UTC](https://discourse.julialang.org/t/add-missing-points-in-a-2d-line/94211/3 "2023-02-07T14:13:52Z")

</div>

Thank you for the hint. Unfortunately I don’t fully understand how to adopt it. Could you give an example?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 7, 2023, 3:08pm UTC](https://discourse.julialang.org/t/add-missing-points-in-a-2d-line/94211/4 "2023-02-07T15:08:37Z")

</div>

Copy and pasting here one of the examples and renaming your sample points as `data`:

```julia
using Dierckx, Plots
t = 1:size(data,1)
spl = ParametricSpline(t, data', bc="extrapolate", s=0.0)
tfine= range(1, size(data,1), 200)
Pfine = evaluate(spl, tfine)
t0, t1 = 12.5, 20.6
P0, P1 = evaluate.((spl,), [t0, t1])

plot(eachrow(Pfine)..., c=:blues)
scatter!(eachcol(data)...,legend=false )
scatter!([P0[1]], [P0[2]], ms=5, mc=:red)
scatter!([P1[1]], [P1[2]], ms=5, mc=:red)

```

 ![Plot_ParametricSpline_Dierckx](https://global.discourse-cdn.com/julialang/original/3X/8/b/8b32b63340ebc9c7b99fc225c033e636f2be5f15.png)

---

<div class="post-metadata">

**Author:** ![Benjamin\_Steinvorth](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@Benjamin\_Steinvorth](https://discourse.julialang.org/u/Benjamin_Steinvorth)\
**Post date:** [February 7, 2023, 3:17pm UTC](https://discourse.julialang.org/t/add-missing-points-in-a-2d-line/94211/5 "2023-02-07T15:17:16Z")

</div>

Thank you for the example!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 7, 2023, 3:18pm UTC](https://discourse.julialang.org/t/add-missing-points-in-a-2d-line/94211/6 "2023-02-07T15:18:33Z")

</div>

I have improved it further, parameterizing using integers, so that it is easier to count the points anti-clockwise and know where to place the new ones.
