Bethose Curve split algorithm

zhaozj2021-02-16  57

The split of the Bayesier curve refers to the polygon of the Bayesier curve into an approximation. It can be used to determine the selection of the Bayser curve, and display the rotation effect of the Beyer curve.

Beyele Curve Brief Introduction:

Each vertex of the Beesier curve has two control points for arc of the curve on the vertices. So the record mode of the vertex array of this function is: control point vertex control point control point vertex control point ....... Therefore, the curve between the two vertices is determined by the two vertices and the control points between the two vertices.

=== Main function polybeziertopolys ===

[Main type of declaration]

Typedef Carray cptarray; // Node dynamic array type

【Parameter Description】

Bezierpts [in] --- Beesier curve vertices and control points

bclose [in] ------ Whether the closed Bayier curve

Polypt [OUT] ----- A number of arrays after split

Precision [in] --- Split Accuracy

Bool Polybeziertopolys (CPTARRAY & Bezierpts,

Bool Bclose, CPTARRAY & POLYPT, INT Precision

{

Polypt.removeall ();

CPTARRAY APT;

INT I, Count = Bezierpts.getsize ();

// From 1, it is because the first is a control point. If the curve is not closed, then the first control point is useless.

/ / Each Bayser Curve is determined by the two control points between the adjacent vertices and between the two vertices, so the frequency is 3 (the last vertex is still used in the next group)

For (i = 1; i

Beziertopoly (& Bezierpts [I], APT, Precision; // Split each section

Polypt.Append (APT); / / Split completion, join an array

}

// If it is a closed curve, you need to make a set of first vertices and the first vertex and the last control point and the first control point.

IF (bclose) {

Cpoint ptbuffer [4];

PTBuffer [0] = Bezierpts [count-2];

PTBuffer [1] = Bezierpts [count-1];

PTBuffer [2] = Bezierpts [0];

PTBuffer [3] = Bezierpts [1];

Beziertopoly (& PTBuffer [0], APT, Precision;

Polypt.Append (APT);

}

Count = polypt.getsize ();

i = 0;

// Filter the neighboring value equal (due to accuracy and error, there may be adjacent split points of the same coordinate value)

While (i

IF (Polypt [i] == POLYPT [i 1]) {

Polypt.Removeat (i 1);

count -;

CONTINUE;

}

i ;

}

Return True;

}

/ / Split the Bessier curve

Bool Incisebezier (CPoint * Psrcpt, Cpoint * PDSTPT)

{

CPoint Buffer [3] [3];

INT I;

For (i = 0; i <3; i ) {

Buffer [0] [i] = psrcpt [i] psrcpt [i 1];

Buffer [0] [i] .x / = 2;

Buffer [0] [i] .y / = 2;

For (i = 0; i <2; i ) {

Buffer [1] [i] = buffer [0] [i] buffer [0] [i 1];

Buffer [1] [i] .x / = 2;

Buffer [1] [i] .y / = 2;

}

Buffer [2] [0] = buffer [1] [0] buffer [1] [1];

Buffer [2] [0] .x / = 2;

Buffer [2] [0] .y / = 2;

PDSTPT [0] = psrcpt [0];

PDSTPT [1] = buffer [0] [0];

PDSTPT [2] = Buffer [1] [0];

PDSTPT [3] = Buffer [2] [0];

PDSTPT [4] = Buffer [1] [1];

PDSTPT [5] = Buffer [0] [2];

PDSTPT [6] = psrcpt [3];

Return True;

}

/ / Split a set of Bethose curve segments

Bool Beziertopoly (CPOINT * PSRCPTS, CPTARRAY & POLYPT, INT PRECISION)

{

Polypt.removeall ();

Polypt.setsize (4);

Polypt [0] = psrcpts [0];

Polypt [1] = psrcpts [1];

Polypt [2] = psrcpts [2];

Polypt [3] = psrcpts [3];

Cpoint PTBuffer [7];

INT I, J, Count = 4;

Bool bexit;

While (true) {

BEXIT = True;

For (i = 0; i

// if (GetBeziergap (& Polypt [i])> precision) {

IF (! Endbeziercut (& Polypt [i], precision) {

Bexit = false;

InciseBezier (& Polypt [i], ptbuffer;

Polypt.Removeat (i 1, 2);

Polypt.insertat (i 1, ptbuffer [1], 5);

For (j = 0; j <4; j )

Polypt [i 2 j] = ptbuffer [2 j];

I = 3;

COUNT = 3;

}

}

IF (bexit)

Break;

}

Count = polypt.getsize ();

i = 0;

While (i

IF (Polypt [i] == POLYPT [i 1]) {

Polypt.Removeat (i 1);

count -;

CONTINUE;

}

i ;

}

Return True;

}

/ / Calculate the portrait and horizontal maximum distance of the two vertices of the Bayesier curve

INT getBeziergap (cpoint * p)

{

INT GAP = 0;

For (int i = 1; i <4; i ) {

IF (ABS (P [i] .X-P [i-1] .x)> GAP)

GAP = ABS (p [i]. x-p [i-1] .x);

IF (ABS (p [i] .y-p [i-1] .y)> GAP)

GAP = ABS (p [i] .y-p [i-1] .y);

}

Return GAP;

}

/ / Judgment whether you can terminate more finely split

BOOL endbeziercut (cpoint * ptbezier, int next) {

Double C, DX, DY, DELT, DELT1, DELT2;

IF (Nextent <2)

NEXTENT = 2;

DX = (Double) (PTBezier [3] .x - ptbezier [0] .x);

DY = (Double) (PTBezier [3] .y - ptbezier [0] .y);

C = DX * PTBezier [0] .y - dy * ptbezier [0] .x;

DELT = (double) Nextent * next * (DY * DY DX * DX);

DELT1 = DY * PTBEZIER [1] .x - dx * ptbezier [1] .y c;

DELT2 = DY * PTBEZIER [2] .x - dx * ptbezier [2] .y c;

DELT1 = DELT1 * DELT1;

DELT2 = DELT2 * DELT2;

IF (DELT1> DELT || DELT2> DELT)

Return False;

Else

Return True;

}

转载请注明原文地址:https://www.9cbs.com/read-22418.html

New Post(0)