Ejemplo n.º 1
0
        public static CsgObject CreateNegativeBevel(double innerRadius, double outerRadius, double height, Alignment alignment = Alignment.z, double extraDimension = defaultExtraRadialDimension, string name = "")
        {
            double         width  = outerRadius - innerRadius;
            List <Vector2> points = new List <Vector2>();

            int numCurvePoints = 6;

            for (int curvePoint = 0; curvePoint <= numCurvePoints; curvePoint++)
            {
                double x = width - Math.Cos((MathHelper.Tau / 4 * curvePoint / numCurvePoints)) * width;
                double y = height - Math.Sin((MathHelper.Tau / 4 * curvePoint / numCurvePoints)) * height;
                points.Add(new Vector2(x, y));
            }
            points.Add(new Vector2(width, 0));
            points.Add(new Vector2(width, height));

            CsgObject bevel = new RotateExtrude(points.ToArray(), innerRadius, alignment, name);

            points.Clear();
            points.Add(new Vector2(0, -extraDimension));
            points.Add(new Vector2(width + extraDimension, -extraDimension));
            points.Add(new Vector2(width + extraDimension, height + extraDimension));
            points.Add(new Vector2(0, height + extraDimension));

            CsgObject cut = new RotateExtrude(points.ToArray(), innerRadius, alignment, name);

            cut = new Align(cut, Face.Bottom, bevel, Face.Bottom, 0, 0, .1);
            //return cut;
            bevel = cut - bevel;

            return(bevel);
        }
Ejemplo n.º 2
0
        public Torus(double innerRadius, double outerRadius, Alignment alignment = Alignment.z, string name = "")
            : base(name)
        {
            double         size   = outerRadius - innerRadius;
            List <Vector2> points = new List <Vector2>();

            int numCurvePoints = 32;

            for (int curvePoint = 0; curvePoint <= numCurvePoints; curvePoint++)
            {
                double x = size - Math.Cos((MathHelper.Tau * curvePoint / numCurvePoints)) * size;
                double y = size - Math.Sin((MathHelper.Tau * curvePoint / numCurvePoints)) * size;
                points.Add(new Vector2(x, y));
            }

            root = new RotateExtrude(points.ToArray(), innerRadius, alignment, name);
            switch (alignment)
            {
            case Alignment.x:
                root = new Rotate(root, y: MathHelper.DegreesToRadians(90));
                break;

            case Alignment.negX:
                root = new Rotate(root, y: MathHelper.DegreesToRadians(-90));
                break;

            case Alignment.y:
                root = new Rotate(root, x: MathHelper.DegreesToRadians(90));
                break;

            case Alignment.z:
                break;

            case Alignment.negZ:
                root = new Rotate(root, x: MathHelper.DegreesToRadians(180));
                break;

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 3
0
		public Torus(double innerRadius, double outerRadius, Alignment alignment = Alignment.z, string name = "")
			: base(name)
		{
			double size = outerRadius - innerRadius;
			List<Vector2> points = new List<Vector2>();

			int numCurvePoints = 32;
			for (int curvePoint = 0; curvePoint <= numCurvePoints; curvePoint++)
			{
				double x = size - Math.Cos((MathHelper.Tau * curvePoint / numCurvePoints)) * size;
				double y = size - Math.Sin((MathHelper.Tau * curvePoint / numCurvePoints)) * size;
				points.Add(new Vector2(x, y));
			}

			root = new RotateExtrude(points.ToArray(), innerRadius, alignment, name);
			switch (alignment)
			{
				case Alignment.x:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.negX:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(-90));
					break;

				case Alignment.y:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.z:
					break;

				case Alignment.negZ:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(180));
					break;

				default:
					throw new NotImplementedException();
			}
		}
Ejemplo n.º 4
0
		public static CsgObject CreateNegativeBevel(double innerRadius, double outerRadius, double height, Alignment alignment = Alignment.z, double extraDimension = defaultExtraRadialDimension, string name = "")
		{
			double width = outerRadius - innerRadius;
			List<Vector2> points = new List<Vector2>();

			int numCurvePoints = 6;
			for (int curvePoint = 0; curvePoint <= numCurvePoints; curvePoint++)
			{
				double x = width - Math.Cos((MathHelper.Tau / 4 * curvePoint / numCurvePoints)) * width;
				double y = height - Math.Sin((MathHelper.Tau / 4 * curvePoint / numCurvePoints)) * height;
				points.Add(new Vector2(x, y));
			}
			points.Add(new Vector2(width, 0));
			points.Add(new Vector2(width, height));

			CsgObject bevel = new RotateExtrude(points.ToArray(), innerRadius, alignment, name);

			points.Clear();
			points.Add(new Vector2(0, -extraDimension));
			points.Add(new Vector2(width + extraDimension, -extraDimension));
			points.Add(new Vector2(width + extraDimension, height + extraDimension));
			points.Add(new Vector2(0, height + extraDimension));

			CsgObject cut = new RotateExtrude(points.ToArray(), innerRadius, alignment, name);
			cut = new Align(cut, Face.Bottom, bevel, Face.Bottom, 0, 0, .1);
			//return cut;
			bevel = cut - bevel;

			return bevel;
		}
Ejemplo n.º 5
0
		public string GetScadOutputRecursive(RotateExtrude.RotateExtrudePrimitive objectToProcess, int level = 0)
		{
			string info = AddRenderInfoIfReqired(objectToProcess);

			string rotate_extrude = "rotate_extrude(convexity = 10, $fn = {0})".FormatWith(NumberOfCylinderSegments);
			string translate = "translate([" + objectToProcess.AxisOffset.ToString() + ", 0, 0])";
			string thingToRotate = "polygon( points=[";
			foreach (Vector2 point in objectToProcess.Points)
			{
				thingToRotate += "[" + point.x.ToString() + ", " + point.y.ToString() + "], ";
			}
			thingToRotate += "] );";

			info += rotate_extrude + translate + thingToRotate + AddNameAsComment(objectToProcess);

			return ApplyIndent(info, level);
		}