Two ways come to my mind for plotting arcs between 3 given points where one of them is the center point.
You explicitely asked for ellipses, so the second approach might be the one for you. Nevertheless, because of its simplicity I will show the simple rotating vector approach as well.
Both approaches work easiest if you have your data in a datablock (check this: gnuplot: load datafile 1:1 into datablock) in order to extract the point coordinates from a certain data line.
1. Rotating & scaling vectors:
a simple way which will always work (but will not necessarily give ellipses): rotate the first vector towards the second vector in the given rotation direction and linearly scale its length. This will result in circle arcs when the two vectors have identical length. Depending on the angles and lengths of the two vectors, it might result in ellipses or spirals.
2. Calculate suitable ellipses:
a bit more complicated is plotting ellipses. I'm not sure, but I guess with the above 3 given points you can draw an infinite number of ellipses through these points. The restriction in the example below is that the longer vector will be taken as the larger elliptic axis. The ellipse will be scaled and rotated such that the endpoint of the smaller vector will be on the ellipse. If the angle difference of the vectors is 0 degrees it will be interpreted as 360 degrees. However, it will be impossible to find an ellipse if the two vectors have an angle difference of 0, 180 or 360 degrees and at the same time different lengths. The code below will nevertheless draw some arcs.
I hope there is no bug in the code and maybe it can be simplified. Suggestions are welcome.
Data: SO57408781_Arcs.dat
File without headerline. Columns: x0 y0 x1 y1 x2 y2 rotation_direction
-7 7 -5 7 -5 7 +1
0 7 2 7 0 9 +1
7 7 9 7 5 7 +1
-4 0 0 4 -2 -2 +1
5 0 8 0 5 5 +1
9 -2 0 -5 7 -7 +1
-7 -7 -5 -7 -4 -9 +1
Code:
### draw ars/ellipses with center point and startpoint to endpoint
reset session
set size square
set angle degrees
FileToDatablock(f,d) = GPVAL_SYSNAME[1:7] eq "Windows" ? \
sprintf('< echo %s ^<^<EOD & type "%s"',d,f) : \
sprintf('< echo "\%s <<EOD" & cat "%s"',d,f) # Linux/MacOS
FILE = 'SO57408781_Arcs.dat'
# file structure
# x0 y0 x1 y1 x2 y2 rotation_direction
load FileToDatablock(FILE,'$Arcs')
# value extraction from datablock
x(i,n) = word($Arcs[i],2*n+1)
y(i,n) = word($Arcs[i],2*n+2)
Direction(i) = word($Arcs[i],7) # rotation direction +1=CCW, -1=CW
# length and angles
L(dx,dy) = sqrt(dx**2 + dy**2)
Angle(x0,y0,x1,y1) = (_dx=x1-x0, _dy=y1-y0, _L=sqrt(_dx**2 + _dy**2), _L==0 ? NaN : \
(_dy>=0 ? acos(_dx/_L) : 360-acos(_dx/_L) ))
# get x,y vector lengths, angles and rotation direction
getXYVAD(n) = (x0=x(n,0), y0=y(n,0), x1=x(n,1), y1=y(n,1), x2=x(n,2), y2=y(n,2), \
v1=L(x1-x0,y1-y0), v2=L(x2-x0,y2-y0), \
a1=Angle(x0,y0,x1,y1), a2=Angle(x0,y0,x2,y2), rd=Direction(n) )
# calculate parameters for the arc
getParamsA(i) = (ca=a2>a1, cd=rd>0, a12=(360*(cd && ca ? 0 : 1) + (a2-a1)*(cd?1:-1))*(cd?1:-1) )
xPosA(i,t) = x0 + (v1*(1-t) + v2*t)*cos(a1+a12*t)
yPosA(i,t) = y0 + (v1*(1-t) + v2*t)*sin(a1+a12*t)
# calculate parameters for the ellipse
getParamsE(n) = (v1>=v2 ? (va=v1, vb=v2, aa=a1, ab=a2) : (va=v2, vb=v1, aa=a2, ab=a1), \
ca = a2>=a1, cd = rd>0, cv = v1>=v2, \
a12 = 360*(a1-a2!=0 && ca==cd ? 0 : cd==cv?1:-1) + (cv?1:-1)*(a2-a1), \
a3 = asin(sqrt(va**2 - (vb*cos(a12))**2) / va), \
a = (abs(a12)<90 ? a3 : abs(a12)<180 ? 180-a3 : abs(a12)<270 ? 180+a3 : 360-a3)*sgn(a12), \
Ra=va, Rb = (abs(a12)==180 || abs(a12)==360) ? Ra : va*vb*abs(sin(a12))/sqrt(va**2 - (vb*cos(a12))**2))
xPosE(i,t) = x0+Ra*cos(a*t)*cos(aa)-Rb*sin(a*t)*sin(aa)
yPosE(i,t) = y0+Ra*cos(a*t)*sin(aa)+Rb*sin(a*t)*cos(aa)
set xrange[-11:11]
set yrange[-11:11]
set key out center top noautotitle
set multiplot layout 1,2
set key title 'Rotating \& scaling vectors'
plot for [i=1:|$Arcs|] [t=0:1] '+' u (getXYVAD(i), getParamsA(i), xPosA(i,t)):(yPosA(i,t)) w l lc "web-green",\
$Arcs u 1:2:($3-$1):($4-$2) w vec lc "blue", \
'' u 1:2:($5-$1):($6-$2) w vec lc "red", \
'' u 1:2 w p pt 7 lc "black" ti "Center point", \
'' u 3:4 w p pt 7 lc "blue" ti "Start point", \
'' u 5:6 w p pt 7 lc "red" ti "End point", \
'' u 1:2:($0+1) w labels offset -0.7,-0.7
set key title 'Drawing ellipses'
plot for [i=1:|$Arcs|] [t=0:1] '+' u (getXYVAD(i), getParamsE(i), xPosE(i,t)):(yPosE(i,t)) w l lc "web-green",\
$Arcs u 1:2:($3-$1):($4-$2) w vec lc "blue", \
'' u 1:2:($5-$1):($6-$2) w vec lc "red", \
'' u 1:2 w p pt 7 lc "black" ti "Center point", \
'' u 3:4 w p pt 7 lc "blue" ti "Start point", \
'' u 5:6 w p pt 7 lc "red" ti "End point", \
'' u 1:2:($0+1) w labels offset -0.7,-0.7
unset multiplot
### end of code
Result:
