# Point to line interpolation using heading in R [closed]

I asked this question at StackOverFlow, but got no answers, so I thought I would try here also:

I can draw a spline through 10 successive points like done in this post

``````set.seed(1)
n <- 10
x <- runif(n)
y <- runif(n)
p <- cbind(x,y)
xlim <- c(min(x) - 0.1*diff(range(x)), c(max(x) + 0.1*diff(range(x))))
ylim <- c(min(y) - 0.1*diff(range(y)), c(max(y) + 0.1*diff(range(y))))
plot(p, xlim=xlim, ylim=ylim)
text(p, labels=seq(n), pos=3)
xspline(x, y, shape = c(0,rep(-1, 10-2),0), border="red")
``````

But is it possible to force the direction of the line in each point to be at a specific heading? - For example, if the heading was 0 in point #2, it would be forced to go straight up, and not as now in a north-easterly direction.

Like on a compass: `0=North`, `90=East`, `180=South` and `270=West`.

For example you could use the following 10 headings:

``````h <- round(runif(n, min = 0, max = 359),0)
``````

Also, the output should be able to be saved as a spatial line.

## closed as unclear what you're asking by ahmadhanb, LaughU, whyzar, Andre Silva, Jochen SchwarzeApr 8 at 14:04

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Idea: if you replace each single point with two points very close together aligned in the direction you want, would that constrain the spline to go through them at that angle? May experiment if I get time, or try it yourself... – Spacedman Apr 5 at 8:47
• Ok seems that idea doesn't work in the general case - sometimes the spline prefers to go through one of the points and then do a tight loop before going through the very adjacent neighbour - it might work better if the direction is close to the natural angle of the spline, but I suspect you might need a different curve system that does have slope constraints you can set explicitly... – Spacedman Apr 5 at 8:55
• Cross-posted as stackoverflow.com/q/55496075/820534. – PolyGeo Jun 20 at 8:24