Skip to content

Instantly share code, notes, and snippets.

@arce
Created March 27, 2020 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arce/2007fbed4457a929eed049159bd31535 to your computer and use it in GitHub Desktop.
Save arce/2007fbed4457a929eed049159bd31535 to your computer and use it in GitHub Desktop.
P5_Arc
static int P5_Arc(lua_State *L) {
const float xc = luaL_checknumber(L, 1);
const float yc = luaL_checknumber(L, 2);
const float radius = luaL_checknumber(L, 3);
const float start = _deg(luaL_checknumber(L, 4));
const float stop = _deg(luaL_checknumber(L, 5));
#ifdef __linux__
const float x1 = xc + radius * STBTT_cos(start);
const float y1 = yc + radius * STBTT_sin(start);
const float x4 = xc + radius * STBTT_cos(stop);
const float y4 = yc + radius * STBTT_sin(stop);
#else
const float x1 = xc + radius * cos(start);
const float y1 = yc + radius * sin(start);
const float x4 = xc + radius * cos(stop);
const float y4 = yc + radius * sin(stop);
#endif
const float ax = x1 - xc;
const float ay = y1 - yc;
const float bx = x4 - xc;
const float by = y4 - yc;
const float q1 = ax * ax + ay * ay;
const float q2 = q1 + ax * bx + ay * by;
#ifdef __linux__
const float k2 = 4/3 * (STBTT_sqrt(2 * q1 * q2) - q2) / (ax * by - ay * bx);
#else
const float k2 = 4/3 * (sqrt(2 * q1 * q2) - q2) / (ax * by - ay * bx);
#endif
const float x2 = xc + ax - k2 * ay;
const float y2 = yc + ay + k2 * ax;
const float x3 = xc + bx + k2 * by;
const float y3 = yc + by - k2 * bx;
return _P5_Bezier(x1,y1,x2,y2,x3,y3,x4,y4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment