예제 #1
0
파일: Arc.cs 프로젝트: unitycoder/Drawing3D
        /// <summary>
        /// gets the angle of a point.
        /// </summary>
        /// <param name="Pt">a point</param>
        /// <returns>the angle</returns>
        public double getAngle(xy Pt)
        {
            Matrix3x3 M = Transformation.invert();
            xy        P = M * Pt;

            return(Math.Atan2(P.y, P.x));
        }
예제 #2
0
 /// <summary>
 /// Constructor, which initializes the bezier curve with startpoint A endpoint B and two controlpoints
 /// </summary>
 /// <param name="A">Startpoint</param>
 /// <param name="ControlPoint1">1. Controlpoint</param>
 /// <param name="ControlPoint2">2.Controlpoint</param>
 /// <param name="B">Endpoint</param>
 public Bezier(xy A, xy ControlPoint1, xy ControlPoint2, xy B)
 {
     Points[0] = A;
     Points[1] = ControlPoint1;
     Points[2] = ControlPoint2;
     Points[3] = B;
 }
예제 #3
0
        /// <summary>
        /// Overrides the Invertmethod
        /// </summary>
        public override void Invert()
        {
            //Inverted = !Inverted;
            xy _A = A;
            xy _B = B;

            //double _dummy = fromParam;
            //double _dummy2 = toParam;
            //fromParam = 1 - toParam;
            //toParam = 1 - _dummy;

            for (int i = 0; i < ControlPoints.Length / 2; i++)
            {
                xy dummy = ControlPoints[i];
                ControlPoints[i] = ControlPoints[ControlPoints.Length - i - 1];
                ControlPoints[ControlPoints.Length - i - 1] = dummy;
            }


            for (int i = 0; i < Knots.Length / 2; i++)
            {
                double dummy = Knots[i];
                Knots[i] = -Knots[Knots.Length - i - 1];
                Knots[Knots.Length - i - 1] = -dummy;
            }
            if (Knots.Length > 0)
            {
                if (((Knots.Length / 2) * 2) != Knots.Length)
                {
                    Knots[Knots.Length / 2] = -Knots[Knots.Length / 2];
                }
            }

            Dirty = true;
        }
예제 #4
0
        void _Trafo()
        {
            if (KeepAspect)
            {
                double _F = 1;
                if ((FloatPoint.X - DiametralFixPoint.X) != 0)
                {
                    _F = (Currentxy.X - DiametralFixPoint.x) / (FloatPoint.X - DiametralFixPoint.X);
                }
                else
                if ((FloatPoint.Y - DiametralFixPoint.Y) != 0)
                {
                    _F = (Currentxy.Y - DiametralFixPoint.Y) / (FloatPoint.Y - DiametralFixPoint.Y);
                }

                CurrentMatrix = Matrix3x3.Translation(DiametralFixPoint) * Matrix3x3.Scale(new xy(_F, _F)) * Matrix3x3.Translation(DiametralFixPoint).invert();
            }
            else
            if (((FloatPoint.X - DiametralFixPoint.X) != 0) && ((FloatPoint.X - DiametralFixPoint.X) != 0))
            {
                xy Factor = new xy(1, 1);
                Factor = new xy((Currentxy.X - DiametralFixPoint.x) / (FloatPoint.X - DiametralFixPoint.X), (Currentxy.Y - DiametralFixPoint.Y) / (FloatPoint.Y - DiametralFixPoint.Y));

                CurrentMatrix = Matrix3x3.Translation(DiametralFixPoint) * Matrix3x3.Scale(new xy(Factor.x, Factor.Y)) * Matrix3x3.Translation(DiametralFixPoint).invert();
            }
        }
예제 #5
0
 /// <summary>
 /// This constructor initializes by three Points A, B and Controlpoint and additionally the weight in the Controlpoint
 /// The weight is set to 1.
 /// </summary>
 /// <param name="A">Point A</param>
 /// <param name="B">Point B</param>
 /// /// <param name="Weight">Wight of the Controlpoint</param>
 /// <param name="ControlPoint">ControlPoint</param>
 public QSpline(xy A, xy B, xy ControlPoint, double Weight) : this()
 {
     this.A            = A;
     this.B            = B;
     this.ControlPoint = ControlPoint;
     this.weight       = Weight;
 }
예제 #6
0
        /// <summary>
        /// This is the same as Operator "*"
        /// </summary>
        /// <param name="M">This matrix is used for the transformation</param>
        /// <returns>Returns a LineType, which is transform by the Matrix M</returns>
        public LineType2d mul(Matrix3x3 M)
        {
            xy Q = M * (P + Direction);
            xy R = M * P;

            return(new LineType2d(R, Q - R));
        }
예제 #7
0
        /// <summary>
        /// Constructor, which initializes the line by the starting point and the endpoint.
        /// </summary>
        ///
        /// <param name="A">Startpoint</param>
        /// <param name="B">Endpoint</param>

        public Line(xy A, xy B)
        {
            Resolution = 1;
            this.A     = A;
            this.B     = B;
            Dirty      = true;
        }
예제 #8
0
        /// <summary>
        /// overrides the <see cref="CtrlEntity.OnMouseMove(HandledMouseEventArgs)"/> method.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public override void OnMouseMove(HandledMouseEventArgs e)
        {
            if (escaped)
            {
                e.Handled = true; return;
            }
            if (CurrentState == State.SecondPoint)
            {
                xy     _B  = new xy(Device.MousePos.X, Device.MousePos.Y);
                double sgn = 1;
                if (_B.Y - A.Y < 0)
                {
                    sgn = -1;
                }
                if (UseViewPortAspect)
                {
                    B = new xy(_B.X, A.Y + sgn * System.Math.Abs(_B.X - A.X) * Aspect);
                }
                else
                {
                    B = new xy(Device.MousePos.X, Device.MousePos.Y);
                }
                { e.Handled = true; return; }
            }
            if (CurrentState == State.FirstPoint)
            {
                A = B = new xy(Device.MousePos.X, Device.MousePos.Y);

                { e.Handled = true; return; }
            }
        }
예제 #9
0
        /// <summary>
        /// overrides the <see cref="CtrlEntity.OnMouseUp(HandledMouseEventArgs)"/> method.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public override void OnMouseUp(HandledMouseEventArgs e)
        {
            if (escaped)
            {
                escaped = false;

                { e.Handled = true; return; }
            }
            if (A.dist(B) < 20)
            {
                e.Handled = true; return;
            }
            RectangleF R      = Utils.ToRectangle(A, B);
            double     Factor = (float)Device.WinControl.ClientSize.Width / R.Width;

            Device.Camera.ZoomTransform(new Point((int)(R.X + R.Width / 2), (int)(R.Y + R.Height / 2)), new Point((int)Device.ViewPort.Width / 2, (int)Device.ViewPort.Height / 2), Factor);
            Device.Selector.RefreshSnapBuffer();
            CurrentState = State.FirstPoint;
            A            = B;
            Device.ForegroundDrawEnable = false;

            Device.OutFitChanged = true;
            Device = null;
            base.OnMouseUp(e);
            return;
        }
예제 #10
0
        static CrossList CrossWithLine(xy A, xy B, CurveArray Array, EdgeLoop E)
        {
            xyArray xyArray = Array.getxyArray();

            if (xyArray[xyArray.Count - 1].dist(xyArray[0]) > 0.0001)   // 17.6 ausgeklammert?-----------
            {
                xyArray.Add(xyArray[0]);
            }
            CrossList CL = CrossWithLine(A, B, xyArray, E);

            for (int i = 0; i < CL.Count; i++)
            {
                Curve C = E[i].ParamCurve;

                CL[i].Param1 = Array.xyArrayIndexToCurveArrayIndex(CL[i].Param1);
                if (CL[i].Param1 == 4)
                {
                }
                int First  = (int)CL[i].Param1;
                int Second = First + 1;
                if (Second >= Array.Count)
                {
                    Second = 0;
                }
                CL[i].A = Array.Value(First);
                CL[i].B = Array.Value(Second);
            }


            return(CL);
        }
예제 #11
0
        /// <summary>
        /// Overrides the Derivation.
        /// <code>
        ///
        ///    xy c = Curve2d.Derivation(t);
        ///    xy v = Curve2d.Value(t);
        ///    return Mapper.uDerivation(v.x, v.y) * c.x + Mapper.vDerivation(v.x, v.y) * c.y;
        ///
        /// </code>
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public override xyz Derivation(double t)
        {
            xy c = Curve2d.Derivation(t);
            xy v = Curve2d.Value(t);

            return(Mapper.uDerivation(v.x, v.y) * c.x + Mapper.vDerivation(v.x, v.y) * c.y);
        }
예제 #12
0
        /*short getPointId(xyf Point)
         * {
         *  //_TmpPoints.Add(Point);
         *  //return (uint)(_TmpPoints.Count - 1);
         *
         *  if (TmpPointArray.ContainsKey(Point))
         *  {
         *      object Ob = TmpPointArray[Point];
         *
         *      return (short)Ob;
         *  }
         *  else
         *  {
         *
         *      TmpPointArray.Add(Point, (uint)_TmpPoints.Count);
         *      _TmpPoints.Add(Point);
         *      return (short)(_TmpPoints.Count - 1);
         *  }
         * }
         */
        bool xCross(xy A, xy B, double x, ref xy Result)
        {
            double dx = B.x - A.x;

            if (System.Math.Abs(dx) < 0.0000000000000001)
            {
                if (System.Math.Abs(x - A.X) < 0.0001)
                {
                }
                return(false);
            }
            double dy = B.y - A.y;
            double _x = (x - A.x);

            if (_x * dx < 0.0000000001)
            {
                return(false);
            }
            if (_x / dx > 1)
            {
                return(false);
            }
            Result = new xy(x, _x * dy / dx + A.y);
            return(true);
        }
예제 #13
0
        /// <summary>
        /// Overrides the <see cref="Surface.ProjectPoint"/> method and calculates a near point on the cylinder.
        /// </summary>
        /// <param name="Point">The u and v relative to the cylinder parameters of a near point.</param>
        /// <returns></returns>
        public override xy ProjectPoint(xyz Point)
        {
            xyz p      = Base.Relativ(Point);
            xy  Result = new xy(Math.Atan2(p.y, p.x) / UFactor, p.z / Height);

            return(Result);
        }
예제 #14
0
        /// <summary>
        /// overrides <see cref="Surface.getCross(LineType, ref double, ref double)"/>.
        /// </summary>
        /// <param name="L">is a crossing line.</param>
        /// <param name="u">parameter u. See also <see cref="Value(double, double)"/> </param>
        /// <param name="v">parameter v. See also <see cref="Value(double, double)"/></param>
        /// <returns></returns>
        public override bool getCross(LineType L, ref double u, ref double v)
        {
            xyz  Pt1   = new xyz(0, 0, 0);
            xyz  Pt2   = new xyz(0, 0, 0);
            bool Cross = Schittpunkt(L.P, L.Direction, Center, new xyz(0, 0, 1), ref Pt1, ref Pt2, Radius);

            if (!Cross)
            {
                return(false);
            }
            if ((Pt1.z > Height + 0.00000001) || (Pt2.z > Height + 0.00000001))
            {
                return(false);
            }
            xy uv = new xy(0, 0);

            if (L.P.dist(Pt1) < L.P.dist(Pt2))
            {
                uv = ProjectPoint(Pt1);
            }
            else
            {
                uv = ProjectPoint(Pt2);
            }

            u = uv.x;
            v = uv.y;
            return(true);
        }
예제 #15
0
        Loxy getLoxy(double UpDown, ref Base Base)
        {
            Loxy Result = new Loxy();

            if ((Curvextruders != null) && (Curvextruders.Count > 0) && (Curvextruders[0].Count > 3))
            {
                xyzArray A = new xyzArray();
                for (int j = 0; j < Curvextruders[0].Count; j++)
                {
                    A.Add(Curvextruders[0][j].Value(0, UpDown));
                }
                xyz N = A.normal();
                Base = Base.DoComplete(Curvextruders[0][0].Value(0, UpDown), N);
                for (int i = 0; i < Curvextruders.Count; i++)
                {
                    xyArray _A = new xyArray();
                    Result.Add(_A);
                    for (int j = 0; j < Curvextruders[i].Count; j++)
                    {
                        xy P = Base.Relativ(Curvextruders[i][j].Value(0, UpDown)).toXY();
                        _A.Add(P);
                    }
                    if (_A.Count > 0)
                    {
                        _A.Add(_A[0]);
                    }
                }
            }
            return(Result);
        }
예제 #16
0
        /// <summary>
        /// internal.
        /// </summary>
        internal static void MeshdrawTriangles2d(OpenGlDevice Device, List <IndexType> Indices, xyf[] Points, xyf[] Texture)
        {
            float dir = 1;

            for (int i = 0; i < Indices.Count; i += 3)
            {
                xy A = new xy(Points[Indices[i + 1]].x - Points[Indices[i]].x, Points[Indices[i + 1]].y - Points[Indices[i]].y);
                xy B = new xy(Points[Indices[i + 2]].x - Points[Indices[i]].x, Points[Indices[i + 2]].y - Points[Indices[i]].y);

                double F = A & B;
                if (System.Math.Abs(F) > 0.0001)
                {
                    if (F < 0)
                    {
                        dir = 1;
                    }
                    else
                    {
                        dir = -1;
                    }
                    break;
                }
            }
            int ID = MeshVertices.Count;

            for (int i = 0; i < Indices.Count; i++)
            {
                MeshIndices.Add((IndexType)(Indices[i] + ID));
            }
            if (MeshVertices.Count + Points.Length > IndexType.MaxValue)
            {
                int CT = (MeshVertices.Count + Points.Length);
                MeshIndices = new List <IndexType>();
                Renew();
                throw new Exception("Points count to large " + CT.ToString());
            }
            for (int i = 0; i < Points.Length; i++)
            {
                MeshVertices.Add(Device.ModelMatrix * new xyz(Points[i].x, Points[i].y, 0).toXYZF());
            }
            xyzf NP = Device.ModelMatrix * new xyzf(0, 0, 0);
            xyzf N  = Device.ModelMatrix * new xyzf(0, 0, dir) - NP;

            for (int i = 0; i < Points.Length; i++)
            {
                MeshNormals.Add(N);
            }
            if (Texture != null)
            {
                MeshTextureCoords.AddRange(Texture);
            }
            MeshMode = PolygonMode.Fill;
            if (Entity.Compiling)
            {
                if (Device.RenderKind == RenderKind.SnapBuffer)
                {
                    MeshCreator.Renew();
                }
            }
        }
예제 #17
0
        /// <summary>
        /// overrides the <see cref="Normal(double, double)"/> method. the direction shows to the left of the curve tangent.
        /// </summary>
        /// <param name="u"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public override xyz Normal(double u, double v)
        {
            Base C   = Base.DoComplete(new xyz(0, 0, 0), Direction);
            xy   Der = Curve.Derivation(u);
            xyz  P   = C.BaseX * Der.x + C.BaseY * Der.y;

            return((P & Direction).normalized() * (-1));
        }
예제 #18
0
        /// <summary>
        /// Overrides the <see cref="Curve.setA"/>-method by setting the endpoint to Points[3].
        /// </summary>
        /// <param name="value">Endpoint</param>
        protected override void setB(xy value)
        {
            xy save = Btang;

            Points[3] = value;
            Btang     = save;
            Dirty     = true;
        }
예제 #19
0
        /// <summary>
        /// Overrides the method <see cref="Curve.setA"/> by setting the value of the Point[0];
        /// </summary>
        /// <returns>Value of A</returns>
        protected override void setA(xy value)
        {
            xy save = Atang;

            Points[0] = value;
            Atang     = save;
            Dirty     = true;
        }
예제 #20
0
 /// <summary>
 /// Overrides the <see cref="Curve.setBtang"/> by setting Points[2] to Points[3] - value;
 /// </summary>
 /// <param name="value">Endtangent</param>
 protected override void setBtang(xy value)
 {
     if (Points.Length > 1)
     {
         Points[Points.Length - 2] = Points[Points.Length - 1] - value;
     }
     Dirty = true;
 }
예제 #21
0
파일: Arc.cs 프로젝트: unitycoder/Drawing3D
        /// <summary>
        /// defines <see cref="aRadius"/> and <see cref="bRadius"/> by keeping the ratio of aRadius and bRadius.
        /// The arc contains the point <b>Pt</b>.
        /// </summary>
        /// <param name="Pt">Point, which lies on the new arc.</param>
        public void SetRadiusbyPoint(xy Pt)
        {
            xy     _PT = Transformation.invert() * Pt;
            double A   = _PT.length();

            Transformation = Matrix3x3.Scale(A, A) * Transformation;
            Dirty          = true;
        }
예제 #22
0
        void SetInterPolationPoints(xy[] InterPolationPoints)
        {
            Points = new xy[3 * (InterPolationPoints.Length - 1) + 1];

            for (int i = 0; i < InterPolationPoints.Length; i++)
            {
                int v = i - 1; if (v < 0)
                {
                    if (Closed(InterPolationPoints))
                    {
                        v = InterPolationPoints.Length - 2;
                    }
                }
                int n = i + 1; if (n >= InterPolationPoints.Length)
                {
                    if (Closed(InterPolationPoints))
                    {
                        n = 1;
                    }
                    else
                    {
                        n = -1;
                    }
                }

                Points[3 * i] = InterPolationPoints[i];
                if ((v >= 0) && (n >= 0))
                {
                    int a = 3 * i + 1;
                    if (a >= Points.Length)
                    {
                        a -= Points.Length - 1;
                    }
                    Points[a] = InterPolationPoints[i] + (InterPolationPoints[n] - InterPolationPoints[v]) * (1f / 5f);


                    int b = 3 * v + 2;
                    if (b >= Points.Length)
                    {
                        b -= Points.Length - 1;
                    }

                    Points[b] = InterPolationPoints[i] - (InterPolationPoints[n] - InterPolationPoints[v]) * (1f / 5f);
                }
                else
                {
                    if (v >= 0)
                    {
                        Points[3 * v + 2] = InterPolationPoints[i];
                    }
                    else
                    {
                        Points[3 * i + 1] = InterPolationPoints[i];
                    }
                }
            }
            Dirty = true;
        }
예제 #23
0
파일: Arc.cs 프로젝트: unitycoder/Drawing3D
 /// <summary>
 /// This constructor initializes <see cref="Alfa"/>=<see cref="Beta"/>=
 /// <see cref="bRadius"/>=<see cref="aRadius"/>= 0 and
 /// <see cref="Center"/> with (0/0);
 ///
 /// </summary>
 public Arc()
 {
     Alfa       = 0;
     Beta       = 0;
     Center     = new xy(0, 0);
     bRadius    = 0;
     aRadius    = 0;
     Resolution = 32;
 }
예제 #24
0
파일: Arc.cs 프로젝트: unitycoder/Drawing3D
 /// <summary>
 ///  Initializes an arc by Center, startangle Alfa, endangle Beta, Orientation Clockwise
 ///  and the radius Radius.
 /// </summary>
 /// <param name="Center">Center of the circle</param>
 /// <param name="Radius">Radius of the circle</param>
 /// <param name="Alfa">Startangle</param>
 /// <param name="Beta">Endangle</param>
 /// <param name="ClockWise">Orientation</param>
 public Arc(xy Center, double Radius, double Alfa, double Beta, bool ClockWise) : this()
 {
     this.Center    = Center;
     this.bRadius   = Radius;
     this.aRadius   = Radius;
     this.Alfa      = Alfa;
     this.Beta      = Beta;
     this.ClockWise = ClockWise;
 }
예제 #25
0
        /// <summary>
        /// Returns a translation matrix. The values are given by the translationvector pt.
        /// </summary>
        /// <param name="pt">Holds the values for the translation</param>
        /// <returns>Translationmatrix</returns>
        static public Matrix3x3 Translation(xy pt)
        {
            Matrix3x3 a = new Matrix3x3(1);

            a.a02 = (float)pt.x;
            a.a12 = (float)pt.y;
            a.a22 = (float)1;
            return(a);
        }
예제 #26
0
파일: Arc.cs 프로젝트: unitycoder/Drawing3D
        /// <summary>
        /// Overrides the <see cref="Curve.setBtang"/>-method.
        /// </summary>
        protected override void setBtang(xy value)
        {
            xy SaveB  = B;
            xy _value = Transformation.invert().multaffin(value);

            Alfa    = Math.Atan2(-_value.x, _value.y);
            Center += (SaveB - B);
            Dirty   = true;
        }
예제 #27
0
        xyz BaryCentric(xy A, xy B, xy C, xy Pt)
        {
            double F = (B - A) & (C - A);
            double z = ((Pt - A) & (Pt - B));
            double x = ((Pt - B) & (Pt - C));
            double y = ((Pt - C) & (Pt - A));

            return(new xyz(x / F, y / F, z / F));
        }
예제 #28
0
        /// <summary>
        /// Overrides the <see cref="Curve.Invert"/>-method.
        /// </summary>

        public override void Invert()
        {
            xy dummy = A;

            A = B;
            B = dummy;

            Dirty = true;
        }
예제 #29
0
        /// <summary>
        /// Overrides the <see cref="Curve.Slice"/>-Method.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        public override void Slice(double from, double to)
        {
            xy _A = Value(from);
            xy _B = Value(to);

            A = _A;
            B = _B;

            Dirty = true;
        }
예제 #30
0
 xy[] GetInterPolationPoints()
 {
     xy[] Result = new xy[(Points.Length) / 3 + 1];
     for (int i = 0; i < Result.Length; i++)
     {
         Result[i] = Points[3 * i];
     }
     Result[Result.Length - 1] = Points[Points.Length - 1];
     return(Result);
 }