public static Path RoundedRectangle(float width, float height, float r, int segs = 1, bool grounded = false) { AXTurtle t = new AXTurtle(); t.mov(-width / 2 + r, -height / 2 + r); t.dir(0); t.fwd(width - 2 * r); t.arcl(90, r, segs); t.fwd(height - 2 * r); t.arcl(90, r, segs); t.fwd(width - 2 * r); t.arcl(90, r, segs); t.fwd(height - 2 * r); t.arcl(90, r, segs); return(t.getPath()); }
public static Path Rectangle(float width, float height, bool isCentered = true) { AXTurtle t = new AXTurtle(); if (isCentered) { t.mov(-width / 2, -height / 2); } else { t.mov(0, 0); } t.dir(90); t.right(width); t.fwd(height); t.left(width); return(t.getPath()); }
// BI_CHAMFER_SIDE public static Path BiChamferSide(float H = 1, float R2 = 0, float R1 = 0, int SegsPer90 = 3, bool BevelOut = true, float Taper = 0, float TopLip = 0, float BotLip = 0, float LipEdge = 0, float LipEdgeBot = 0, int Segs = 1 ) { // DERIVED VARIABLES /* * float o = H-(R1+R2); * float a = Mathf.Atan2(o, Taper) * Mathf.Rad2Deg; * * float d = Mathf.Sqrt(Taper*Taper + o*o); * float dr = Mathf.Abs(R1-R2); * float b = Mathf.Asin(dr/d) * Mathf.Rad2Deg; * * // his is the slope of the line or straight edge of the extrude side. * float dir = (R2 > R1) ? 180 - (a+b) : 270 - (a + (90-b)); * * float s = Mathf.Sqrt(d*d - dr*dr); */ float o = H - (R1 + R2); float l = Taper + R2 - R1; float a = Mathf.Atan2(o, l) * Mathf.Rad2Deg; float d = Mathf.Sqrt(l * l + o * o); float dr = Mathf.Abs(R1 - R2); float s = Mathf.Sqrt(d * d - dr * dr); float b = Mathf.Asin(dr / d) * Mathf.Rad2Deg; // his is the slope of the line or straight edge of the extrude side. float dir = (R2 > R1) ? 180 - (a + b) : 270 - (a + (90 - b)); // START_X //float startX = 0; float startX = (R2 > R1) ? R2 - R1 : 0; startX -= BotLip; if (!BevelOut) { startX -= R1; } float startY = LipEdgeBot; // DRAW SHAPE AXTurtle t = new AXTurtle(); t.mov(startX, startY); t.dir(90); if (LipEdgeBot != 0) { t.back(LipEdgeBot); } t.dir(0); if (BotLip > 0) { t.fwd(BotLip); } // Chamfer Bottom if (R1 > 0) { t.arcl(dir, R1, Mathf.FloorToInt((dir / 90f) * SegsPer90)); } else { t.dir(dir); } for (int i = 0; i < Segs; i++) { t.fwd(s / Segs); } // Chamfer Top if (R2 > 0) { t.arcl((180 - dir), R2, Mathf.FloorToInt(((180 - dir) / 90f) * SegsPer90)); } else { t.dir(180); } // TopLip if (TopLip > 0) { t.fwd(TopLip); } if (LipEdge != 0) { t.left(LipEdge); } return(t.path); }
// TAPERED_SIDE public static Path Tapered_Side(float H = 1, float RBase = .5f, float RTop = .4f, float HoleRadius = .05f, float ShiftY = .05f, float RBevel = 0, int SegsPer90 = 3, int SideSegs = 1 ) { //Debug.Log("RBevel="+RBevel); // DERIVED VARIABLES float T = RBase - RTop; float a = Mathf.Atan2(H, T); // * Mathf.Rad2Deg; float a_degs = a * Mathf.Rad2Deg; //Debug.Log ("H="+H+", T="+ T +", a_degs="+ a_degs ); float cos_a = Mathf.Cos(a); float sin_a = Mathf.Sin(a); //float s1 = RBevel * (H/T); float s1 = RBevel * cos_a; float s2 = (RBevel + s1) * (T / H); float t1 = RBevel + s2; //float s3 = RBevel * sin_a; //float t2 = s3-s1; float M = H - 2 * RBevel; //Debug.Log ("t2="+t2+", H="+H+", M="+M); float S = (sin_a == 0) ? M : (M / sin_a); //Debug.Log("H="+H+", O="+O+", d="+d + " a="+a_degs+", sin_a="+sin_a +", cos_a="+cos_a); // float bottomLip = RBase - t1 - HoleRadius; // float topLip = RTop - t2 - HoleRadius; float taperAng = 180 - a_degs; // START_X //float startX = 0; float startX = -(t1); // (R2 > R1) ? R2-R1 : 0; //Debug.Log("t1="+t1); //startX -= BotLip; float startY = 0; // ShiftY; // DRAW SHAPE AXTurtle t = new AXTurtle(); t.mov(startX, startY); //t.dir(90); //if (HoleDepth != 0) // t.back(HoleDepth); t.dir(0); // if (bottomLip > 0) // t.fwd(bottomLip); // Chamfer Bottom if (RBevel > 0) { t.arcl(taperAng, RBevel, Mathf.FloorToInt((taperAng / 90f) * SegsPer90)); } else { t.dir(taperAng); } // float vsegment = S/((float)SideSegs); // for (int i=0; i<SideSegs; i++) // t.fwd(vsegment); t.fwd(S); // Chamfer Top if (RBevel > 0) { t.arcl((a_degs), RBevel, Mathf.FloorToInt(((a_degs) / 90f) * SegsPer90)); } else { t.dir(180); } // TopLip // if (topLip > 0) // t.fwd(topLip); // if (HoleDepth != 0) // t.left(HoleDepth); //Debug.Log ("dir = " + t.rotation +"rBase = " + RBase + ", rTop = " + RTop + "T = " + T + ", LAST "+ t.path [t.path.Count - 1].X); return(t.path); }