Пример #1
0
        // static Create method follows the API convention and parent should be first argument
        public static GyroidRelaxGraphics Create(Gyroid gyroid)
        {
            var widget = new GyroidRelaxGraphics(gyroid);

            widget.Initialize();
            return(widget);
        }
Пример #2
0
        protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect)
        {
            base.OnExecute(command, context, buttonRect);
            gyroid = new Gyroid(angleForce, vForce, uAngleForce, uTouchForce, averageVForce, averageTabAngleForce);
            Window window = Window.ActiveWindow;

            window.SetTool(new GyroidRelax(gyroid, this));
        }
Пример #3
0
        public GyroidPropertiesButtonCapsule(string name, string text, System.Drawing.Image image, string hint, RibbonCollectionCapsule parent, ButtonSize buttonSize)
            : base(name, text, image, hint, parent, buttonSize)
        {
            Values[Resources.LawsonTabAngleForce]        = new RibbonCommandValue(angleForce);
            Values[Resources.LawsonVAlignmentForce]      = new RibbonCommandValue(vForce);
            Values[Resources.LawsonUAngleForce]          = new RibbonCommandValue(uAngleForce);
            Values[Resources.LawsonUTouchForce]          = new RibbonCommandValue(uTouchForce);
            Values[Resources.LawsonVAverageForce]        = new RibbonCommandValue(averageVForce);
            Values[Resources.LawsonTabAngleAverageForce] = new RibbonCommandValue(averageTabAngleForce);

            if (gyroid == null)
            {
                gyroid = new Gyroid(angleForce, vForce, uAngleForce, uTouchForce, averageVForce, averageTabAngleForce);
            }
        }
Пример #4
0
 public static Graphic GetGraphic(Gyroid gyroid)
 {
     return(gyroid.GetGraphic());
 }
Пример #5
0
 // creates a new custom object and a wrapper for it
 protected GyroidRelaxGraphics(Gyroid gyroid)
     : base(Window.ActiveWindow.Scene as Part)
 {
     this.gyroid = gyroid;
 }
Пример #6
0
        //		double cursorScale = 0.01;

        public GyroidRelax(Gyroid gyroid, GyroidRelaxButtonCapsule buttonCapsule)
            : base(InteractionMode.Solid)
        {
            this.gyroid        = gyroid;
            this.buttonCapsule = buttonCapsule;
        }
Пример #7
0
        public void Iterate()
        {
            Iteration++;

            //var newVParameters = new List<List<double>>(steps + 1);
            //var backupVParameters = new List<List<double>>(steps + 1);
            //var newTabAngles = new List<List<double>>(steps + 1);

            for (int i = 0; i < steps; i++)
            {
                //newVParameters.Add(new List<double>(steps + 1));
                //backupVParameters.Add(new List<double>(steps + 1));
                //newTabAngles.Add(new List<double>(steps + 1));
                for (int j = 0; j <= steps; j++)
                {
                    //		newVParameters[i].Add(vParameters[i][j]);
                    //		backupVParameters[i].Add(vParameters[i][j]);
                    //newTabAngles[i].Add(tabAngles[i][j]);
                }
            }

            double cumulativeErrorTally = 0;

            MaxError = 0;
            for (int i = 0; i <= steps; i++)
            {
                for (int j = 0; j <= steps; j++)
                {
                    Vector grad = Gradient(points[i, j]);
                    points[i, j] = points[i, j] + grad.Z * Direction.DirZ / 100;

#if false
                    bool swap      = j % 2 == 0;
                    int  iOtherDir = swap ? -1 : 1;
                    int  iOther    = i + iOtherDir;

                    Circle baseCircle = GetTabFromPoints(true, i, j, iOther);
                    Circle circle0    = GetTabFromPoints(true, iOther, j - 1, i);
                    Circle circle1    = GetTabFromPoints(true, iOther, j + 1, i);

                    double distance0 = (baseCircle.Frame.Origin - circle0.Frame.Origin).Magnitude - baseCircle.Radius - circle0.Radius;
                    double distance1 = (baseCircle.Frame.Origin - circle1.Frame.Origin).Magnitude - baseCircle.Radius - circle1.Radius;
                    cumulativeErrorTally += distance0 * distance0 + distance1 * distance1;
                    MaxError              = Math.Max(Math.Abs(distance0), MaxError);
                    MaxError              = Math.Max(Math.Abs(distance1), MaxError);

                    double angleAdjust = (distance0 + distance1) / 2 * AngleForce / GetSpanAt(i, j) / baseCircle.Radius;                     // / GetSpanAt(i, j) / baseCircle.Radius; // / baseCircle.Radius;
                    newTabAngles[i][j] -= angleAdjust;

                    newTabAngles[i][j - 1] -= angleAdjust / 2;
                    newTabAngles[i][j + 1] -= angleAdjust / 2;

                    double iAngle = AddInHelper.AngleBetween(
                        circle0.Frame.Origin - baseCircle.Frame.Origin,
                        circle1.Frame.Origin - baseCircle.Frame.Origin
                        );

                    double vOffset = (distance1 - distance0) * VForce;
                    //double uAngleOffset = -(Math.PI / 2 - Math.Abs(iAngle)) * UAngleForce;
                    double uAngleOffset = -(Math.PI * 2 / 3 - Math.Abs(iAngle)) * UAngleForce;

                    Circle circleV      = GetTabFromPoints(true, iOther, j, i);
                    double distanceV    = (baseCircle.Frame.Origin - circleV.Frame.Origin).Magnitude - baseCircle.Radius - circleV.Radius;
                    double uTouchOffset = -distanceV * UTouchForce;

                    double averageOffset = 0;
                    double averageAngle  = 0;
                    double count         = 0;


                    foreach (int ii in new int[] { i, iOther })
                    {
                        foreach (int jj in new int[] { j - 1, j + 1 })
                        {
                            averageAngle += GetTabFromPoints(true, ii, jj, ii == i ? iOther : i).Radius;
                            count++;
                        }
                    }

                    averageOffset += GetSpanAt(i - 1, j);
                    averageOffset += GetSpanAt(i + 1, j);
                    averageOffset += GetSpanAt(i, j - 1);
                    averageOffset += GetSpanAt(i, j + 1);
                    averageOffset /= 4;

                    averageOffset  = averageOffset / count - GetSpanAt(i, j);
                    averageOffset *= -AverageVForce / 2;

                    averageAngle        = averageAngle / count - baseCircle.Radius;
                    newTabAngles[i][j] -= averageAngle * AverageTabAngleForce;

                    double size = 1;                    // (points[i][j + 1] - points[i][j]).Magnitude;
                    double slip = (uAngleOffset + averageOffset + uTouchOffset) * size;

                    newVParameters[i][j]     += vOffset + slip;
                    newVParameters[i][j + 1] += vOffset - slip;

                    newVParameters[i][j - 1] += (vOffset + slip) / 2;
                    newVParameters[i][j + 2] += (vOffset - slip) / 2;

                    //				double oldSpan = (points[i][j + 1] - points[i][j]).Magnitude;
                    //				double newSpan = (points[i][j + 1] - points[i][j]).Magnitude;


                    Trace.WriteIf(Iteration % 400 == 0, tabAngles[i][j] + " ");
                    //					Trace.WriteIf(Iteration % 400 == 0, iAngle + " ");
                    //					Trace.WriteIf(Iteration % 400 == 0, GetSpanAt(i,j) + " ");
#endif
                }
                Trace.WriteLineIf(Iteration % 400 == 0, "");
            }

#if false
            // Average antipodal points
            // for l(i, j),
            // l(i, j) == l(-i, pi+j)* == l(i+2pi, -j) == l(-i-2pi, pi-j)*
            // Where * means x=x, y=-y, z=-z
            for (int i = 0; i < iSteps; i++)
            {
                for (int j = 0; j < jSteps / 2; j++)
                {
                    double average = (
                        newVParameters[i][j] +
                        newVParameters[-i][j + jSteps / 2] - Math.PI +
                        (j < 2 ? 0 : 2 * Math.PI) - newVParameters[i + iSteps][-j + 1] +
                        Math.PI - newVParameters[-i - iSteps][-j + jSteps / 2 + 1]
                        ) / 4;

                    newVParameters[i][j] = average;
                    newVParameters[-i][j + jSteps / 2] = average + Math.PI;
                    newVParameters[i + iSteps][-j + 1] = (j < 2 ? 0 : 2 * Math.PI) - average;
                    newVParameters[-i - iSteps][-j + jSteps / 2 + 1] = Math.PI - average;

                    average = (
                        tabAngles[i][j] +
                        tabAngles[-i][j + jSteps / 2 + 1] +
                        tabAngles[i + iSteps][-j] +
                        tabAngles[-i - iSteps][-j + jSteps / 2 + 1]
                        ) / 4;

                    tabAngles[i][j] = average;
                    tabAngles[-i][j + jSteps / 2 + 1]           = average;
                    tabAngles[i + iSteps][-j]                   = average;
                    tabAngles[-i - iSteps][-j + jSteps / 2 + 1] = average;
                }
            }
#endif

            CumulativeError = Math.Sqrt(cumulativeErrorTally / (steps * steps * 2));
            //	Trace.WriteLine(lastCumulativeError);

            // We're not calculating the points for the last iteration.  Whatevs.
            //		vParameters = newVParameters;

            //tabAngles = newTabAngles;

#if false
            for (int i = 0; i < iSteps; i++)
            {
                double u = 2 * Math.PI * (double)i / iSteps;
                for (int j = 0; j < jSteps; j++)
                {
                    points[i][j] = Gyroid.Evaluate(PointUV.Create(vParameters[i][j], u), p, q, circleAngle, inverseOffset, true) * scale;
                    //		Trace.WriteLine(string.Format("{0} {1} {2}", i, j, tabAngles[i][j]));
                }
            }
#endif
        }