简体   繁体   English

C ++。 将定义2点的图形贝塞尔曲线调用转换为定义3点的调用?

[英]c++. Convert drawing bezier curve calls with 2 points defined to calls with 3 points defined?

link to theory 理论联系

C and c mean curves with 3 points defined. C和c表示定义了3个点的曲线。

S and s mean curves with 2 points defined. S和s平均曲线定义了2个点。

The relevant functions are (monkSVG + monkVG/openVG): 相关功能为(monkSVG + monkVG / openVG):

    void OpenVG_SVGHandler::onPathCubic( float x1, float y1, float x2, float y2, float x3, float y3 ) { 
        VGubyte seg = VG_CUBIC_TO | openVGRelative();
        VGfloat data[6];

        data[0] = x1; data[1] = y1;
        data[2] = x2; data[3] = y2;
        data[4] = x3; data[5] = y3;
        vgAppendPathData( _current_group->current_path->path, 1, &seg, data);

    }

    void OpenVG_SVGHandler::onPathSCubic( float x2, float y2, float x3, float y3 ) {
        VGubyte seg = VG_SCUBIC_TO | openVGRelative();
        VGfloat data[4];

        data[0] = x2; data[1] = y2;
        data[2] = x3; data[3] = y3;
        vgAppendPathData( _current_group->current_path->path, 1, &seg, data);

    }

The problem is the second function (with 2 points) result image look likes incorrect. 问题是第二个功能(具有2个点)结果图像看起来不正确。 So I want to try to replace it with a function which look likes workable. 因此,我想尝试用看起来可行的功能替换它。

I tried to store a point from a previous step but it gives an incorrect result: 我试图存储上一步的一个点,但结果不正确:

float x2 = d_string_to_float( c, &c );
float y2 = d_string_to_float( c, &c );
float x3 = d_string_to_float( c, &c );
float y3 = d_string_to_float( c, &c );
float x1 = 2 * prevX - x2;
float y1 = 2 * prevY - x2;
_handler->onPathCubic(x1, y1, x2, y2, x3, y3);
prevX = x3;
prevY = y3;

Let's name the variables slightly differently. 让我们对变量命名略有不同。 You have two cubic Bezier curves, one with four points A, B, C, D, and the other with points E, F, G, H. 您有两条三次贝塞尔曲线,一条具有四个点A,B,C,D,而另一个具有点E,F,G,H。

The SCubic function tries to ensure that D=E and (C+F)/2 = D. SCubic函数试图确保D = E和(C + F)/ 2 =D。

The first time you call onPathCubic, x1 = B, x2 = C, x3 = D. A is previously set. 第一次调用onPathCubic时,x1 = B,x2 = C,x3 =D。A是预先设置的。 (I only discuss x for conciseness, but you would need x and y). (为简洁起见,我仅讨论x,但是您将需要x和y)。

The second time you call onPathCubic, you need to compute F, and G and H are specified. 第二次调用onPathCubic时,需要计算F,并指定G和H。 How can you compute F? 如何计算F? Well, F = 2 * D - C. 好吧,F = 2 * D-C。

Let's look at how our letters map to variables in the second call: 让我们看看在第二个调用中我们的字母如何映射到变量:

D = E = prevX D = E = preX
F = x1 F = x1
G = x2 G = 2
H = x3 高= x3

This is a problem, because you're not storing C, so you don't have enough information to compute F. 这是一个问题,因为您没有存储C,因此您没有足够的信息来计算F。

My solution is to write code similar to the same in another library: 我的解决方案是在另一个库中编写类似的代码:

link 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM