Created
May 21, 2022 17:05
-
-
Save thu0x31/d1fd1be1a305d256911b943886bc39ea to your computer and use it in GitHub Desktop.
Revisions
-
thu0x31 created this gist
May 21, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ function int[] arcFrom2Points(vector centerPos; float radius; int totalPoints; vector startPos, endPos; string direction) { float threshold = 0.01; if(radius < threshold) { return{}; } float TWO_PI = PI * 2; vector v1 = normalize(startPos - centerPos); vector v2 = normalize(endPos - centerPos); float startRad = atan2(v1.z, v1.x); // (atan2(v2.z, v2.x) - startRad) - (atan2(v1.z, v1.x) - startRad) ベクトルを{1,0,0}に初期化する float rad = startRad*2 - atan2(v2.z, v2.x) - atan2(v1.z, v1.x); if((rad < 0) && (direction == "Left")) { rad += TWO_PI; } else if((rad > 0) && (direction == "Right")) { rad -= TWO_PI; } int points[]; for(int i = 0; i <= totalPoints; i++) { vector pos = set( centerPos.x + radius * cos(startRad - i * (rad/totalPoints)), centerPos.y, centerPos.z + radius * sin(startRad - i * (rad/totalPoints)) ); int pointN = addpoint(0, pos); setpointattrib(0, "arcLength", pointN, rad*TWO_PI); setpointattrib(0, "dictCenter", pointN, normalize(centerPos - pos)); if(direction == "Right") { setpointattrib(0, "N", pointN, normalize(centerPos - pos)); } if(direction == "Left") { setpointattrib(0, "N", pointN, normalize(pos - centerPos)); } push(points, pointN); } // debug // addprim(0, "polyline", addpoint(0, centerPos + v1 * radius), addpoint(0, centerPos)); // addprim(0, "polyline", addpoint(0, centerPos + v2 * radius), addpoint(0, centerPos)); return points; }