I want to draw two or many curved lines from fixed start point to another fixed end point on map. So, I started with geodesic but it draws overlapping lines. Then I tried to draw trajectory but not very useful as points could be any where in the world. How can I achieve this? I am using python and javascript. The below image is something I am aiming for (map is not added but imagine as if it is there :)). Also, is there any way to add directional arrow? Please help.
1 Answer
This could be done with Bézier curves. Here is the python library to create Bézier curves.
import bezier
import numpy
import matplotlib
x1 = [0.0, 1.0, 2.0]
y1 = [0.0, 1.0, 0.0]
x2 = [0.0, 1.0, 2.0]
y2 = [0.1, 2.0, 0.1]
nodes1 = numpy.asfortranarray([x1, y1])
nodes2 = numpy.asfortranarray([x2, y2])
curve1 = bezier.Curve(nodes1, degree=2)
ax = curve1.plot(100, color='r', alpha=None, ax=None)
curve2 = bezier.Curve(nodes2, degree=2)
curve2.plot(100, color='g', alpha=None, ax=ax)
number_of_point = 15
s_vals = numpy.linspace(0.0, 1.0, number_of_point)
[curve2_values_x, curve2_values_y] = curve2.evaluate_multi(s_vals)
print('curve2_values_x=', curve2_values_x, end='\n'*2)
print('curve2_values_y=', curve2_values_y)
matplotlib.pyplot.plot(x1, y1, 'ro')
matplotlib.pyplot.plot(x2, y2, 'go')
matplotlib.pyplot.plot(curve2_values_x, curve2_values_y, 'b+')
matplotlib.pyplot.show()
-
-
-
This is really helpful. Do you know how to densify the curve. My main goal is to use the list of (x,y) geometry and pass to create polyline.– SuryaOct 31, 2019 at 10:56
-