Arc division algorithm

I am looking for a sample from a texture along a circular arc in the fragment shader. Such rules exclude recursive methods such as this .

I came up with several different ways to do this: two that seem most reasonable (given the starting position p, center c, radius r = length(c-p), angle (arc length) thetain radians and positions N):

1) Turn the pc vector about c by theta/N, Ntimes: this requires building a rotation matrix that will be reused: cost - two trigger functions, a N2x2 matrix is ​​multiplied, Nor so vector subtractions

2) Find the chord length of one segment intersecting a sector: its length 2*r*sin(theta/2). As soon as I have the first vector, I can rotate it and add it to the previous position to "step" along my arc. The problem with this method is that I still don't know the expression to get the orientation of my length vector 2*r*sin(theta/2). Even if I did, I would probably need trigger functions to create it. I still need to rotate it so that it takes me to still create the rotation matrix. Ugh.

Are there any other methods that I could consider?

+1
source share
1 answer

, , . , . , 2D- , .

void f(float cx, float cy, float px, float py, float theta, int N)
{
    float dx = px - cx;
    float dy = py - cy;
    float r2 = dx * dx + dy * dy;
    float r = sqrt(r2);
    float ctheta = cos(theta/(N-1));
    float stheta = sin(theta/(N-1));
    std::cout << cx + dx << "," << cy + dy << std::endl;
    for(int i = 1; i != N; ++i)
    {
        float dxtemp = ctheta * dx - stheta * dy;
        dy = stheta * dx + ctheta * dy;
        dx = dxtemp;
        std::cout << cx + dx << "," << cy + dy << std::endl;
    }
}

N, , . N theta, .

: , , , - 1).

+3

All Articles