根据cairo示例代码,以下代码
double x=25.6, y=128.0;
double x1=102.4, y1=230.4,
x2=153.6, y2=25.6,
x3=230.4, y3=128.0;
cairo_move_to (cr, x, y);
cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
cairo_set_line_width (cr, 10.0);
cairo_stroke (cr);
cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
cairo_set_line_width (cr, 6.0);
cairo_move_to (cr,x,y); cairo_line_to (cr,x1,y1);
cairo_move_to (cr,x2,y2); cairo_line_to (cr,x3,y3);
cairo_stroke (cr);
Run Code Online (Sandbox Code Playgroud)
可以生成曲线和两条粉红色的线条.
但那需要4个点,(x,y),(x1,y1),(x2,y2),(x3,y3)
如果我只有x,y和x3,y3(曲线的起点和终点),是否有任何数学公式可以生成那些粉红色的线而不知道x1,y1和x2,y2?
编辑:
它适用于我通过以下方式生成曲线的情况.
cairo_move_to (cr, x, y);
cairo_curve_to (cr, x, y3, x3, y, x3, y3);
Run Code Online (Sandbox Code Playgroud)
只需提出要点:
中点可以计算为:
P mid =(x 1 + x 3)/ 2,(y 1 + y 3)/ 2
double x1=25.6, y1=128.0;
double x3=153.6, y3=25.6;
double xm = (x1+x3)/2;
double ym = (y1+y3)/2;
//rotate Pm by 90degrees around p1 to get p2
double x2 = -(ym-y1) + y1;
double y2 = (xm-x1) + x1;
//rotate Pm by 90degrees around p3 to get p4
double x4 = -(ym-y3) + y3;
double y4 = (xm-x3) + x3;
Run Code Online (Sandbox Code Playgroud)