devNotes 3-01-2017 Procedural Arch

     public static MeshDraft Arc_Cube(float arch_Angle, float theta_Pos, float lenX, float lenY, int spar_Segments, float inner_Height, float inner_Width, float rounding_Radius, int rounding_Segments, float dist_From_Axis)
        {
            var draft = new MeshDraft { name = "Arc_Cube - VU Button Work" };

            Vector3 center_loc = Pos_on_Ellipse(dist_From_Axis, lenX, lenY, theta_Pos);
            Vector3 left_loc = Pos_on_Ellipse(dist_From_Axis, lenX, lenY, theta_Pos+arch_Angle/2);
            Vector3 right_loc = Pos_on_Ellipse(dist_From_Axis, lenX, lenY, theta_Pos - arch_Angle / 2);

            Vector3 left_Pointing  = Vector3.Cross(Vector3.forward, Vector3.Normalize(left_loc));
            Vector3 right_Pointing = Vector3.Cross(Vector3.Normalize(right_loc),Vector3.forward);

            //Left End Plate
            Vector3 vH = Vector3.Normalize(left_loc);
            Vector3 vW = Vector3.forward;
            float h = inner_Height/2;
            float w = inner_Width / 2;

            List<Vector3> vEndPlate_Left = new List<Vector3>();
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius);
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius - vW * w);
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius - vW * w - vH * h);
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius - vH * h);
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius + vW * w - vH * h);
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius + vW * w);
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius + vW * w + vH * h);
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius + vH * h);
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius - vW * w + vH * h);
            vEndPlate_Left.Add(left_loc + left_Pointing * rounding_Radius - vW * w);

            draft.Add(TriangleFan(vEndPlate_Left));

            //Right End Plate
            vH = Vector3.Normalize(right_loc);

            List<Vector3> vEndPlate_Right = new List<Vector3>();
            
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius);
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius - vW * w);
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius - vW * w + vH * h);
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius + vH * h);
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius + vW * w + vH * h);
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius + vW * w);
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius + vW * w - vH * h);
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius - vH * h);
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius - vW * w - vH * h);
            vEndPlate_Right.Add(right_loc + right_Pointing * rounding_Radius - vW * w);

            draft.Add(TriangleFan(vEndPlate_Right));
            float arch_delta_ang = arch_Angle / spar_Segments;

            vH = Vector3.Normalize(left_loc);
            vW = Vector3.forward;

            List<Vector3> vCrossSec_L = new List<Vector3>();
            List<Vector3> norm_CSec_L = new List<Vector3>();

            float arch_ang_inner = 0;
            float ang = 0;
            float dAng = Mathf.PI / (2*rounding_Segments);
            Vector3 vCirc;

            vCrossSec_L.Add(left_loc - vW * (w + rounding_Radius));
            norm_CSec_L.Add(-vW);
            for (int i = 0; i<rounding_Segments; i++)
            {
                vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                vCrossSec_L.Add(left_loc - vW * w + vH * h - vCirc.x * vW + vCirc.y * vH);
                norm_CSec_L.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                ang += dAng;
            }

            vCrossSec_L.Add(left_loc + vH * (h + rounding_Radius));
            norm_CSec_L.Add(vH);
            for (int i = 0; i < rounding_Segments; i++)
            {
                vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                vCrossSec_L.Add(left_loc + vW * w + vH * h - vCirc.x * vW + vCirc.y * vH);
                norm_CSec_L.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                ang += dAng;
            }

            vCrossSec_L.Add(left_loc + vW * (w + rounding_Radius));
            norm_CSec_L.Add(vW);

            for (int i = 0; i < rounding_Segments; i++)
            {
                vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                vCrossSec_L.Add(left_loc + vW * w - vH * h - vCirc.x * vW + vCirc.y * vH);
                norm_CSec_L.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                ang += dAng;
            }

            vCrossSec_L.Add(left_loc - vH * (h + rounding_Radius));
            norm_CSec_L.Add(-vH);

            for (int i = 0; i < rounding_Segments; i++)
            {
                vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                vCrossSec_L.Add(left_loc - vW * w - vH * h - vCirc.x * vW + vCirc.y * vH);
                norm_CSec_L.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                ang += dAng;
            }
            vCrossSec_L.Add(left_loc - vW * (w + rounding_Radius));
            norm_CSec_L.Add(-vW);

            for (int j = 0; j < spar_Segments; j++)
            {
                List<Vector3> vCrossSec_R = new List<Vector3>();
                List<Vector3> norm_CSec_R = new List<Vector3>();
                arch_ang_inner -= arch_delta_ang;
                center_loc = Pos_on_Ellipse(dist_From_Axis, lenX, lenY, theta_Pos + arch_Angle / 2 + arch_ang_inner);
                vH = Vector3.Normalize(center_loc);

                ang = 0;

                vCrossSec_R.Add(center_loc - vW * (w + rounding_Radius));
                norm_CSec_R.Add(-vW);
                for (int i = 0; i < rounding_Segments; i++)
                {
                    vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                    vCrossSec_R.Add(center_loc - vW * w + vH * h - vCirc.x * vW + vCirc.y * vH);
                    norm_CSec_R.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                    ang += dAng;
                }

                vCrossSec_R.Add(center_loc + vH * (h + rounding_Radius));
                norm_CSec_R.Add(vH);
                for (int i = 0; i < rounding_Segments; i++)
                {
                    vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                    vCrossSec_R.Add(center_loc + vW * w + vH * h - vCirc.x * vW + vCirc.y * vH);
                    norm_CSec_R.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                    ang += dAng;
                }

                vCrossSec_R.Add(center_loc + vW * (w + rounding_Radius));
                norm_CSec_R.Add(vW);
                for (int i = 0; i < rounding_Segments; i++)
                {
                    vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                    vCrossSec_R.Add(center_loc + vW * w - vH * h - vCirc.x * vW + vCirc.y * vH);
                    norm_CSec_R.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                    ang += dAng;
                }

                vCrossSec_R.Add(center_loc - vH * (h + rounding_Radius));
                norm_CSec_R.Add(-vH);

                for (int i = 0; i < rounding_Segments; i++)
                {
                    vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                    vCrossSec_R.Add(center_loc - vW * w - vH * h - vCirc.x * vW + vCirc.y * vH);
                    norm_CSec_R.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                    ang += dAng;
                }
                vCrossSec_R.Add(center_loc - vW * (w + rounding_Radius));
                norm_CSec_R.Add(-vW);


                draft.Add(Band_Flip(vCrossSec_L, norm_CSec_L, vCrossSec_R, norm_CSec_L));
                vCrossSec_L = vCrossSec_R;
                norm_CSec_L = norm_CSec_R;
            }

            //CAPS
            Vector3 cap_loc = left_loc;
            Vector3 pointing = left_Pointing;
            float dir = 1;
            for (int k = 0; k < 2; k++)
            {
                if(k == 1)
                {
                    cap_loc = right_loc;
                    pointing = right_Pointing;
                    dir = -1;
                }

                vCrossSec_L = new List<Vector3>();
                norm_CSec_L = new List<Vector3>();
                vH = Vector3.Normalize(cap_loc);

                float incRad = rounding_Radius / rounding_Segments;
                float accRad = 0;

                vCrossSec_L.Add(cap_loc - vW * (w + rounding_Radius));
                norm_CSec_L.Add(-vW);
                for (int i = 0; i < rounding_Segments; i++)
                {
                    vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                    vCrossSec_L.Add(cap_loc - vW * w + vH * h - vCirc.x * vW + vCirc.y * vH);
                    norm_CSec_L.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                    ang += dAng;
                }

                vCrossSec_L.Add(cap_loc + vH * (h + rounding_Radius));
                norm_CSec_L.Add(vH);
                for (int i = 0; i < rounding_Segments; i++)
                {
                    vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                    vCrossSec_L.Add(cap_loc + vW * w + vH * h - vCirc.x * vW + vCirc.y * vH);
                    norm_CSec_L.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                    ang += dAng;
                }

                vCrossSec_L.Add(cap_loc + vW * (w + rounding_Radius));
                norm_CSec_L.Add(vW);

                for (int i = 0; i < rounding_Segments; i++)
                {
                    vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                    vCrossSec_L.Add(cap_loc + vW * w - vH * h - vCirc.x * vW + vCirc.y * vH);
                    norm_CSec_L.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                    ang += dAng;
                }

                vCrossSec_L.Add(cap_loc - vH * (h + rounding_Radius));
                norm_CSec_L.Add(-vH);

                for (int i = 0; i < rounding_Segments; i++)
                {
                    vCirc = PTUtils.PointOnCircle3_XY2(rounding_Radius, ang);
                    vCrossSec_L.Add(cap_loc - vW * w - vH * h - vCirc.x * vW + vCirc.y * vH);
                    norm_CSec_L.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH));
                    ang += dAng;
                }
                vCrossSec_L.Add(cap_loc - vW * (w + rounding_Radius));
                norm_CSec_L.Add(-vW);

                for (int j = 0; j < rounding_Segments; j++)
                {
                    List<Vector3> vCrossSec_R = new List<Vector3>();
                    List<Vector3> norm_CSec_R = new List<Vector3>();
                    arch_ang_inner -= arch_delta_ang;
                    //center_loc = Pos_on_Ellipse(dist_From_Axis, lenX, lenY, theta_Pos + arch_Angle / 2 + arch_ang_inner);
                    //vH = Vector3.Normalize(left_loc);

                    ang = 0;

                    //float incRad = rounding_Radius / rounding_Segments;
                    //float accRad = 0;
                    accRad += incRad;
                    //New_Rad = Radius * sin(Arccos(Inc_Accum / Radius))

                    float newRad = rounding_Radius * Mathf.Sin(Mathf.Acos(accRad / rounding_Radius));

                    if (j == rounding_Segments - 1) newRad = 0;

                    vCrossSec_R.Add(cap_loc - vW * (w + newRad) + accRad* pointing);
                    norm_CSec_R.Add(-vW);
                    for (int i = 0; i < rounding_Segments; i++)
                    {
                        vCirc = PTUtils.PointOnCircle3_XY2(newRad, ang);
                        vCrossSec_R.Add(cap_loc - vW * w + vH * h - vCirc.x * vW + vCirc.y * vH + accRad * pointing);
                        norm_CSec_R.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH + accRad * pointing));
                        ang += dAng;
                    }

                    vCrossSec_R.Add(cap_loc + vH * (h + newRad) + accRad * pointing);
                    norm_CSec_R.Add(vH);
                    for (int i = 0; i < rounding_Segments; i++)
                    {
                        vCirc = PTUtils.PointOnCircle3_XY2(newRad, ang);
                        vCrossSec_R.Add(cap_loc + vW * w + vH * h - vCirc.x * vW + vCirc.y * vH + accRad * pointing);
                        norm_CSec_R.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH + accRad * pointing));
                        ang += dAng;
                    }

                    vCrossSec_R.Add(cap_loc + vW * (w + newRad) + accRad * pointing);
                    norm_CSec_R.Add(vW);
                    for (int i = 0; i < rounding_Segments; i++)
                    {
                        vCirc = PTUtils.PointOnCircle3_XY2(newRad, ang);
                        vCrossSec_R.Add(cap_loc + vW * w - vH * h - vCirc.x * vW + vCirc.y * vH + accRad * pointing);
                        norm_CSec_R.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH + accRad * pointing));
                        ang += dAng;
                    }

                    vCrossSec_R.Add(cap_loc - vH * (h + newRad) + accRad * pointing );
                    norm_CSec_R.Add(-vH);

                    for (int i = 0; i < rounding_Segments; i++)
                    {
                        vCirc = PTUtils.PointOnCircle3_XY2(newRad, ang);
                        vCrossSec_R.Add(cap_loc - vW * w - vH * h - vCirc.x * vW + vCirc.y * vH + accRad * pointing);
                        norm_CSec_R.Add(Vector3.Normalize(-vCirc.x * vW + vCirc.y * vH + accRad * pointing));
                        ang += dAng;
                    }
                    vCrossSec_R.Add(cap_loc - vW * (w + newRad) + accRad * pointing);
                    norm_CSec_R.Add(-vW);

                    if (k == 0)
                    {
                        draft.Add(Band_Flip(vCrossSec_R, norm_CSec_R, vCrossSec_L, norm_CSec_L));
                    }
                    else
                    {
                        draft.Add(Band_Flip( vCrossSec_L, norm_CSec_L, vCrossSec_R, norm_CSec_R));
                    }

                    vCrossSec_L = vCrossSec_R;
                    norm_CSec_L = norm_CSec_R;
                }
            }

            return draft;    
        }

 

procedural_rounded_button

arch_angle