English 中文(简体)
如何在不了解4点的情况下提取曲线?
原标题:How to draw a curve without knowing 4 points?

http://cairographics.org/samples/curve_to/“rel=“nofollow noreferer”

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);

can generate the curve and two pink lines.

enter image description here

但这需要4点(x,y),(x1,y1),(x2,y2),(x3,y3)

If I only have x,y and x3, y3 (start and end points of the curve), is there any math formula to generate those pink lines without knowing x1,y1 and x2,y2?

http://www.ohchr.org。

就我以下列方式产生曲线的情况而言。

cairo_move_to (cr, x, y);
cairo_curve_to (cr, x, y3, x3, y, x3, y3);
最佳回答

仅提出以下几点:

  • start with your two known points, (x1,y1) and (x3,y3):

“entergraph

  • join the two lines:

“entergraph

  • create P2 as halfway between P1 and P3:

enter image description here

  • now rotate P3 90° clockwise:

“entergraph

  • do with same with P4, create it halfway between P1 and P3:

enter image description here

  • rotate P4 90° clockwise:

“entergraph

  • Now you have your four points, and can draw your bézier curve:

enter image description here


中点可计算为:

<>P<>><>><>>>><>>>>>> = (x<1>/sub>+x<>3)/2 , (y/sub><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;
问题回答

并非除非你提供某种制约,可用来确定汇线的位置。 两个终点本身只能界定一个直线部分。

粉碎线是两端的病媒。 如果没有这些病媒,这两点之间的“接触”只是一条直线(除非你们有其他一些界定信息)。

如果你没有(x1,y1)和(x2,y2),你就可以将(x3,y3)作为汇线的终点从(x,y)到反之。 他们ll在你黑线上,应该直线。

如果曲线由功能加以界定,则计算衍生物,因为你接近尾声,沿这一角度划出细微线。





相关问题
GTK:Button onHover effect different on Linux and Windows

I have a GTK button on my GUI app, however, the hover effects are different for both Linux and Windows: Heres Linux: Heres Windows: I did not do anything fancy to the animations, in fact, the ...

Gtk Draw Bitmap

I want to draw an image on a window using Cairo. How can I load a bmp or png from disk and create a brush from it? The code below shows where drawing should be made. The expose signal is attached to ...

How do I render *parts* of a svg file?

I want to render parts of a svg file by name but for the life of me I cannot figure out how to do so (using python + gtk). Here s the svg file in question: http://david.bellot.free.fr/svg-cards/files/...

How can I "best fit" an arbitrary cairo (pycairo) path?

It seems like given the information in stroke_extents() and the translate(x, y) and scale(x, y) functions, I should be able to take any arbitrary cairo (I m using pycairo) path and "best fit" it. In ...

How do I do text wrapping in pyCairo + Pango?

What I need pyCairo to do is : generate an image of size 100x100 containing some text and an image from filesystem as background the text should be within a box which has text wrapping of size 20x20 ...

wxGraphicsContext dreadfully slow on Windows

I ve implemented a plotter using wxGraphicsContext. The development was done using wxGTK, and the graphics was very fast. Then I switched to Windows (XP) using wxWidgets 2.9.0. And the same code is ...

热门标签