public static Coord NudgeCoordXZForYAxisAngleAndRadius(int yAngleDegrees, int radius) { float x = (CrudeTrig.Sin(yAngleDegrees)); // x uses Sin. float z = (CrudeTrig.Cos(yAngleDegrees)); //how close to a 45 degrees "like" (i.e. 45, 135, 225, 315) angle is yAngDegrees? int ang45 = yAngleDegrees % 90 - 45; ang45 *= ang45 < 0 ? -1 : 1; ang45 = 45 - ang45; //to get the "radius point" on the square //stretch radius proportional to lerp 1<-->SQRT2 ang45 // CONSIDER: more efficient: radius += .4142 * (ang45/45f) ? float radStretch = (float)radius * Mathf.Lerp(1f, SQROOT_TWO, (float)(ang45 / 45.0f)); x *= radStretch; z *= radStretch; //Wrangle inaccuracies if (x < 0) { x -= .5f; x = x < -(float)radius ? -(float)radius : x; } else { x += .5f; x = x > (float)radius ? (float)radius : x; } if (z < 0) { z -= .5f; z = z < -(float)radius ? -(float)radius : z; } else { z += .5f; z = z > (float)radius ? (float)radius : z; } return(new Coord((int)x, 0, (int)z)); }
private IEnumerator testTrig() { int testAng = 35; while (true) { // int radTwo = testCrudeTrigeRadius * 2; // int angleCount = (radTwo + 1) * (radTwo + 1) - (radTwo - 1) * (radTwo - 1); //square count also // int angIncr = (int)(360/(angleCount)); // if (testCrudeTrigeRadius > 3) // { // angIncr = 2; // } // b.bug("ang incr: " + angIncr); // List<int> angs = CrudeTrig.SquareAnglesForRadiusAndAngle(testCrudeTrigeRadius, testAng); List <int> angs = CrudeTrig.SquareAnglesForFullPerimeter(testCrudeTrigeRadius, testAng); // for(int angDegrees = 0;angDegrees < 360 ;angDegrees += angIncr ) foreach (int angDegrees in angs) { // int angDegrees = 0; Coord nudgeCo = CoordRadarUtil.NudgeCoordXZForYAxisAngleAndRadius(angDegrees, testCrudeTrigeRadius); currentTestTrigCoord = nudgeCo; testTrigCoords.Add(nudgeCo); yield return(new WaitForSeconds(.05f)); } testCrudeTrigeRadius++; if (testCrudeTrigeRadius > 5) { testCrudeTrigeRadius = 1; testAng -= 90; } // return true; } }