This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function seqSearch(x,A,n) | |
local i=0 | |
while (i < n) do | |
if (x == A[i]) then | |
return i | |
end | |
i = i + 1 | |
end | |
return -1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static float getApproximationFactor(float angleStart, float angleEnd) { | |
int arc = angleEnd - angleStart; | |
if (abs(arc) > M_PI) { | |
arc -= M_PI * 2; | |
arc /= M_PI * 2; | |
} | |
return (4 / 3) * tan(arc / 4); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is an 8-year-old question, but one that I recently struggled with, so I thought I'd share what I came up with. I spent a lot of time trying to use solution (9) from this text and couldn't get any sensible numbers out of it until I did some Googling and learned that, apparently, there were some typos in the equations. Per the corrections listed in this blog post, given the start and end points of the arc ([x1, y1] and [x4, y4], respectively) and the the center of the circle ([xc, yc]), one can derive the control points for a cubic bezier curve ([x2, y2] and [x3, y3]) as follows: | |
ax = x1 – xc | |
ay = y1 – yc | |
bx = x4 – xc | |
by = y4 – yc | |
q1 = ax * ax + ay * ay | |
q2 = q1 + ax * bx + ay * by | |
k2 = 4/3 * (√(2 * q1 * q2) – q2) / (ax * by – ay * bx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I stumbled upon this problem recently. I compiled a solution from the articles mentioned here in the form of a module. | |
It accepts start angle, end angle, center and radius as input. | |
It approximates small arcs (<= PI/2) pretty well. If you need to approximate something arcs from PI/2 to 2*PI you can always break them in parts < PI/2, calculate the according curves and join them afterward. | |
This solution is start and end angle order agnostic - it always picks the minor arc. | |
As a result you get all four points you need to define a cubic bezier curve in absolute coordinates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pull requests | |
Issues | |
Marketplace | |
Explore | |
@arce | |
mgthomas99 | |
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
write = io.write | |
function Array(arg1) | |
local table = (type(arg1) == "table") and arg1 or {} | |
local _table = table | |
table = {} | |
local metatable = { | |
__newindex = function(table,k,v) | |
_table[k+1] = v | |
end, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//full userdata | |
extern "C" int newarray(lua_State* L) | |
{ | |
int n = luaL_checkint(L, 1); | |
size_t nbytes = sizeof(CharArray) + (n - 1)*sizeof(char); | |
CharArray* a = (CharArray*)lua_newuserdata(L, nbytes); | |
a->size = n; | |
return 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* An example of an OpenGL animation loop using the Win32 API. Also | |
demonstrates palette management for RGB and color index modes and | |
general strategies for message handling. */ | |
#include <windows.h> /* must include this before GL/gl.h */ | |
#include <GL/gl.h> /* OpenGL header file */ | |
#include <stdio.h> | |
HDC hDC; /* device context */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://bl.ocks.org/arce/06627a44f961cfe92ef984fa80ce80a7 | |
void setup() { | |
size(640,480); | |
} | |
void draw() { | |
background(243); | |
ui.begin(); |
NewerOlder