Exemple #1
0
        public void dome(Vector2 a, Vector2 b, float segs = 3, float tension = .3f)
        {
            float dt = 1f / (float)segs;

            Vector2 d = b - a;


            float hanx = tension * d.x;
            float hany = tension * d.y;

            // bezier 1

            //Vector2 ha = new Vector2(a.x+hanx,  a.y);
            //Vector2 hb = new Vector2(b.x,     b.y-hany);

            Vector2 ha = new Vector2(a.x, a.y + hany);
            Vector2 hb = new Vector2(b.x - hanx, b.y);



            Vector2 pt;

            for (float i = 1; i <= segs; i++)
            {
                pt = AXTurtle.bezierValue(a, ha, hb, b, i * dt);
                path.Add(new IntPoint(sup(pt.x), sup(pt.y)));
            }
        }
Exemple #2
0
        public void cymareversa(Vector2 a, Vector2 b, float segs = 3, float tension = .3f)
        {
            float dt = 1f / (float)segs;

            Vector2 d = b - a;

            Vector2 midpt = a + d / 2;

            float hanx = tension * d.x;
            float hany = tension * d.y;

            Vector2 pt;

            // bezier 1

            Vector2 ha1 = new Vector2(a.x, a.y + hanx);
            Vector2 ha2 = new Vector2(midpt.x - hanx, midpt.y - hany / 2);

            for (float i = 1; i <= segs; i++)
            {
                pt = AXTurtle.bezierValue(a, ha1, ha2, midpt, i * dt);
                path.Add(new IntPoint(sup(pt.x), sup(pt.y)));
            }

            // bezier 2

            Vector2 hb1 = new Vector2(midpt.x + hanx, midpt.y + hany / 2);
            Vector2 hb2 = new Vector2(b.x, b.y - hany);

            for (float i = 1; i <= segs; i++)
            {
                pt = AXTurtle.bezierValue(midpt, hb1, hb2, b, i * dt);
                path.Add(new IntPoint(sup(pt.x), sup(pt.y)));
            }
        }
Exemple #3
0
        public void bezier(Vector2 a, Vector2 b, Vector2 c, Vector2 d, int segs)
        {
            assertPath(a);

            float dt = 1f / (float)segs;

            for (float i = 1; i <= segs; i++)
            {
                Vector2 pt = AXTurtle.bezierValue(a, b, c, d, i * dt);
                path.Add(new IntPoint(sup(pt.x), sup(pt.y)));
            }


            if (c.x == d.x && c.y != d.y)
            {
                if (c.y > d.y)
                {
                    dir(270);
                }
                else
                {
                    dir(90);
                }
            }
            else
            {
                dir(Mathf.Atan2(d.y - c.y, d.x - c.x) * Mathf.Rad2Deg);
            }
        }
Exemple #4
0
        public void onion(Vector2 a, Vector2 b, float segs = 3, float tension = .9f)
        {
            // VALIDATION: Assert at least 3 sides
            segs = Mathf.Max(segs, 3);

            float dt = 1f / (float)segs;

            Vector2 d = b - a;

            Vector2 midpt = a + d / 2;

            midpt.x = a.x - .2f * d.x;
            midpt.y = a.y + .5f * d.y;

            float hanx = 1.2f * Mathf.Abs(tension * d.x);
            float hany = .20f * Mathf.Abs(tension * d.y);



            Vector2 pt;


            // bezier 1

            Vector2 ha1 = new Vector2(a.x + hanx, a.y);
            Vector2 ha2 = new Vector2(midpt.x + hanx, midpt.y - hany);

            for (float i = 1; i <= segs; i++)
            {
                pt = AXTurtle.bezierValue(a, ha1, ha2, midpt, i * dt);
                path.Add(new IntPoint(sup(pt.x), sup(pt.y)));
            }


            // bezier 2

            Vector2 hb1 = new Vector2(midpt.x - hanx, midpt.y + hany);
            Vector2 hb2 = new Vector2(b.x, b.y - .5f * hany);

            for (float i = 1; i <= segs; i++)
            {
                pt = AXTurtle.bezierValue(midpt, hb1, hb2, b, i * dt);
                path.Add(new IntPoint(sup(pt.x), sup(pt.y)));
            }
        }
        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());
        }
Exemple #7
0
        // 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);
        }
        // ECHINUS

        public static Path Echinus(
            float H          = 1,
            float RBase      = .5f,
            float RTop       = .4f,
            float TaperBase  = .4f,
            float RBevBase   = .4f,
            float RBevTop    = .4f,
            float HanBase    = .4f,
            float HanTop     = .4f,
            float HoleRadius = .05f,
            float HoleDepth  = .05f,
            int SegsPer90    = 5,
            int SideSegs     = 1
            )
        {
            //Debug.Log("RBevel="+RBevel);

            // DERIVED VARIABLES

            // BASE
            float a_degs = 180 - TaperBase;
            float a      = a_degs * Mathf.Deg2Rad;
            float cos_a  = Mathf.Cos(a);
            float sin_a  = Mathf.Sin(a);


            float s1 = RBevBase * cos_a;
            float SY = RBevBase + s1;
            float SX = SY * cos_a;

            float t1 = RBevBase + SX;

            //float bottomLip = RBase - t1 - HoleRadius;

            float HanBaseX = -SX - HanBase * cos_a;
            float HanBaseY = SY + HanBase * sin_a;

            // TOP

            float W = RTop - RBase;

            float b = Mathf.Atan2(H, W);                    // * Mathf.Rad2Deg;

            float cos_b  = Mathf.Cos(b);
            float sin_b  = Mathf.Sin(b);
            float b_degs = b * Mathf.Rad2Deg;

            float d1 = RBevTop * cos_b;
            float DY = H - (RBevTop + d1);
            float DX = DY * (W / H);


            //float TaperTop = Mathf.Atan2(H, W);

            float HanTopX = DX - HanTop * cos_b;
            float HanTopY = DY - HanTop * sin_b;



            //Debug.Log("H="+H+", O="+O+", d="+d + " a="+a_degs+", sin_a="+sin_a +", cos_a="+cos_a);



            // START_X
            //float startX = 0;
            //float startX = -(t1+bottomLip);// (R2 > R1) ? R2-R1 : 0;
            float startX = -(t1);            // (R2 > R1) ? R2-R1 : 0;

            //startX -= BotLip;



            float startY = 0;


            // 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

            //Debug.Log("TaperBase="+TaperBase+", RBevBase=" + RBevBase);


            if (RBevBase > 0)
            {
                t.arcl(TaperBase, RBevBase, Mathf.FloorToInt((TaperBase / 90f) * SegsPer90));
            }
            else
            {
                t.dir(TaperBase);
            }

            Vector2 A  = new Vector2(-SX, SY);
            Vector2 AH = new Vector2(HanBaseX, HanBaseY);
            Vector2 BH = new Vector2(HanTopX, HanTopY);
            Vector2 B  = new Vector2(DX, DY);


            t.bezier(A, AH, BH, B, SegsPer90);

//			for (int i=0; i<SideSegs; i++)
//				t.fwd(s/SideSegs);

            // Chamfer Top

            if (RBevTop > 0)
            {
                t.arcl((a_degs + 90), RBevTop, Mathf.FloorToInt(((b_degs) / 90f) * SegsPer90));
            }
            else
            {
                t.dir(180);
            }

//			// TopLip
//			if (topLip > 0)
//				t.fwd(topLip);
//
//
//			if (HoleDepth != 0)
//				t.left(HoleDepth);


            return(t.path);
        }