// This method performs the Point3D operations
        private void PerformOperation(object sender, RoutedEventArgs e)
        {
            RadioButton li = (sender as RadioButton);

            // Strings used to display the results
            String syntaxString, resultType, operationString;

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
            switch (li.Name)
            {   //begin switch

                case "rb1":
                    {
                        // Translates a Point3D by a Vector3D using the overloaded + operator.
                        // Returns a Point3D.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Vector3D vector1 = new Vector3D(20, 30, 40);
                        Point3D pointResult = new Point3D();

                        pointResult = point1 + vector1;
                        // point3DResult is equal to (30, 35, 41)

                        // Displaying Results
                        syntaxString = "pointResult = point1 + vector1;";
                        resultType = "Point3D";
                        operationString = "Adding a 3D Point and a 3D Vector";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb2":
                    {
                        // Translates a Point3D by a Vector3D using the static Add method.
                        // Returns a Point3D.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Vector3D vector1 = new Vector3D(20, 30, 40);
                        Point3D pointResult = new Point3D();

                        pointResult = Point3D.Add(point1, vector1);
                        // pointResult is equal to (30, 35, 41)

                        // Displaying Results
                        syntaxString = "pointResult = Point3D.Add(point1, vector1);";
                        resultType = "Point3D";
                        operationString = "Adding a 3D Point and a 3D Vector";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb3":
                    {
                        // Subtracts a Vector3D from a Point3D using the overloaded - operator.
                        // Returns a Point3D.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Vector3D vector1 = new Vector3D(20, 30, 40);
                        Point3D pointResult = new Point3D();

                        pointResult = point1 - vector1;
                        // pointResult is equal to (-10, -25, -39)

                        // Displaying Results
                        syntaxString = "pointResult = point1 - vector1;";
                        resultType = "Point3D";
                        operationString = "Subtracting a Vector3D from a Point3D";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb4":
                    {
                        // Subtracts a Vector3D from a Point3D using the static Subtract method.
                        // Returns a Point3D.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Vector3D vector1 = new Vector3D(20, 30, 40);
                        Point3D pointResult = new Point3D();

                        pointResult = Point3D.Subtract(point1, vector1);
                        // pointResult is equal to (-10, -25, -39)

                        // Displaying Results
                        syntaxString = "pointResult = Point3D.Subtract(point1, vector1);";
                        resultType = "Point3D";
                        operationString = "Subtracting a Vector3D from a Point3D";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb5":
                    {
                        // Subtracts a Point3D from a Point3D using the overloaded - operator.
                        // Returns a Vector3D.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Point3D point2 = new Point3D(15, 40, 60);
                        Vector3D vectorResult = new Vector3D();

                        vectorResult = point1 - point2;
                        // vectorResult is equal to (-5, -35, -59)

                        // Displaying Results
                        syntaxString = " vectorResult = point1 - point2;";
                        resultType = "Vector3D";
                        operationString = "Subtracting a Point3D from a Point3D";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb6":
                    {
                        // Subtracts a Point3D from a Point3D using the static Subtract method.
                        // Returns a Vector3D.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Point3D point2 = new Point3D(15, 40, 60);
                        Vector3D vectorResult = new Vector3D();

                        vectorResult = Point3D.Subtract(point1, point2);
                        // vectorResult is equal to (-5, -35, -59)

                        // Displaying Results
                        syntaxString = "vectorResult = Point3D.Subtract(point1, point2);";
                        resultType = "Vector3D";
                        operationString = "Subtracting a Point3D from a Point3D";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb7":
                    {
                        // Offsets the X, Y and Z values of a Point3D.

                        Point3D point1 = new Point3D(10, 5, 1);

                        point1.Offset(20, 30, 40);
                        // point1 is equal to (30, 35, 41)

                        // Note: This operation is equivalent to adding a point
                        // to vector with the corresponding X,Y, Z values.

                        // Displaying Results
                        syntaxString = "point1.Offset(20, 30, 40);";
                        resultType = "Point3D";
                        operationString = "Offsetting a Point3D";
                        ShowResults(point1.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb8":
                    {
                        // Multiplies a Point3D by a Matrix.
                        // Returns a Point3D.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Point3D pointResult = new Point3D();
                        Matrix3D matrix1 = new Matrix3D(10, 10, 10, 0, 20, 20, 20, 0, 30, 30, 30, 0, 5, 10, 15, 1);

                        pointResult = point1 * matrix1;
                        // pointResult is equal to (235, 240, 245)

                        // Displaying Results
                        resultType = "Point3D";
                        syntaxString = "pointResult = point1 * matrix1;";
                        operationString = "Multiplying a Point3D by a Matrix3D";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb9":
                    {
                        // Multiplies a Point3D by a Matrix.
                        // Returns a Point3D.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Point3D pointResult = new Point3D();
                        Matrix3D matrix1 = new Matrix3D(10, 10, 10, 0, 20, 20, 20, 0, 30, 30, 30, 0, 5, 10, 15, 1);

                        pointResult = Point3D.Multiply(point1, matrix1);
                        // pointResult is equal to (235, 240, 245)

                        // Displaying Results
                        resultType = "Point3D";
                        syntaxString = "pointResult = Point3D.Multiply(point1, matrix1);";
                        operationString = "Multiplying a Point3D by a Matrix";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb10":
                    {
                        // Checks if two Point3Ds are equal using the overloaded equality operator.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Point3D point2 = new Point3D(15, 40, 60);
                        Boolean areEqual;

                        areEqual = (point1 == point2);
                        // areEqual is False

                        // Displaying Results
                        syntaxString = "areEqual = (point1 == point2);";
                        resultType = "Boolean";
                        operationString = "Checking if two 3D points are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb11":
                    {
                        // Checks if two Point3D structures are equal using the static Equals method.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Point3D point2 = new Point3D(15, 40, 60);
                        Boolean areEqual;

                        areEqual = Point3D.Equals(point1, point2);
                        // areEqual is False

                        //Displaying Results
                        syntaxString = "areEqual = Point3D.Equals(point1, point2);";
                        resultType = "Boolean";
                        operationString = "Checking if 3D two points are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }
                case "rb12":
                    {
                        // Compares an Object and a Point3D for equality using the non-static Equals method.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Point3D point2 = new Point3D(15, 40, 60);
                        Boolean areEqual;

                        areEqual = point1.Equals(point2);
                        // areEqual is False.  point2 is a Point3D structure, but it is not equal to point1.

                        // Displaying Results
                        syntaxString = "areEqual = point1.Equals(point2);;";
                        resultType = "Boolean";
                        operationString = "Checking if two 3D points are equal";
                        ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb13":
                    {
                        // Converts a string representation of a 3-D point into a Point3D structure.

                        Point3D pointResult = new Point3D();

                        pointResult = Point3D.Parse("1,3,5");
                        // pointResult is equal to (1,3,5)

                        // Displaying Results
                        syntaxString = "ointResult = Point3D.Parse(\"1,3,5\");";
                        resultType = "Matrix";
                        operationString = "Converting a string into a Point3D structure.";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb14":
                    {
                        // Checks if two Point3Ds are not equal using the overloaded inequality operator.

                        Point3D point1 = new Point3D(10, 5, 1);
                        Point3D point2 = new Point3D(15, 40, 60);
                        Boolean areNotEqual;

                        areNotEqual = (point1 != point2);
                        // areNotEqual is True

                        // Displaying Results
                        syntaxString = "areNotEqual = (point1 != point2);";
                        resultType = "Boolean";
                        operationString = "Checking if two 3D points are not equal";
                        ShowResults(areNotEqual.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb15":
                    {
                        // Point3D Subtraction
                        // instantiate variables
                        Point3D point1 = new Point3D();
                        Point3D point2 = new Point3D(15, 40, 60);
                        Vector3D vector1 = new Vector3D(20, 30, 40);
                        Point3D pointResult = new Point3D();
                        Vector3D vectorResult = new Vector3D();

                        // defining x,y,z of point1
                        point1.X = 10;
                        point1.Y = 5;
                        point1.Z = 1;

                        vectorResult = Point3D.Subtract(point1, point2);
                        // vectorResult is equal to (-5, -35, -39)

                        vectorResult = point2 - point1;
                        // vectorResult is equal to (5, 35, 59)

                        //pointResult = Point3D.Subtract(point1, vector1);
                        //  pointResult is equal to (-10, -25, -39)

                        pointResult = vector1 - point1;
                        //  pointResult is equal to (10, 25, 39)

                        // Displaying Results
                        syntaxString = "areNotEqual = (point1 != point2);";
                        resultType = "Boolean";
                        operationString = "Checking if two 3D points are not equal";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                default:
                    break;
            } //end switch
        }
示例#2
0
        private void moveToAngles(double alpha, double beta, double gamma) {
            RotateTransform3D bodyCoxaTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), alpha));
            bodyCoxaTransform.CenterX = 0;
            bodyCoxaTransform.CenterY = 0;
            bodyCoxaTransform.CenterZ = 0;
            Model.Transform = bodyCoxaTransform;

            RotateTransform3D coxaFemurTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), beta));
            coxaFemurTransform.CenterX = bodyCoxaLen;
            coxaFemurTransform.CenterY = 0;
            coxaFemurTransform.CenterZ = 0;
            femurTibiaLink.Model.Transform = coxaFemurTransform;
            femurTibiaJoint.Model.Transform = coxaFemurTransform;
            foot.Model.Transform = coxaFemurTransform;


            var group3Dtransformation = new Transform3DGroup();
            group3Dtransformation.Children.Add(femurTibiaLink.Model.Transform);
            Point3D origin = group3Dtransformation.Transform(new Point3D(bodyCoxaLen, 0, femurLen));
            RotateTransform3D femurTibiaTransform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), gamma));
            femurTibiaTransform.CenterX = origin.X;
            femurTibiaTransform.CenterY = origin.Y;
            femurTibiaTransform.CenterZ = origin.Z;
            group3Dtransformation.Children.Add(femurTibiaTransform);
            tibiaFootLink.Model.Transform = group3Dtransformation;
            foot.Model.Transform = group3Dtransformation;

            var p = new Point3D(bodyCoxaJoint.Point2.X, bodyCoxaJoint.Point2.Y, bodyCoxaJoint.Point2.Z);
            p.Offset(0, 0, 1.5 * jointDiameter);
            coxaAngleLabel.Position = p;
            coxaAngleLabel.Text = String.Format("{0:N1}°", alpha);

            var q = new Point3D(coxaFemurTransform.CenterX, coxaFemurTransform.CenterY, coxaFemurTransform.CenterZ);
            q.Offset(0,0, -2 * jointDiameter);
            femurAngleLabel.Transform = bodyCoxaTransform;
            femurAngleLabel.Position = q;
            femurAngleLabel.Text = String.Format("{0:N1}°", beta);

            var r = new Point3D(femurTibiaTransform.CenterX, femurTibiaTransform.CenterY, femurTibiaTransform.CenterZ);
            r.Offset(0, 0, 1.5 * jointDiameter);
            tibiaAngleLabel.Position = r;
            tibiaAngleLabel.Transform = bodyCoxaTransform;
            tibiaAngleLabel.Text = String.Format("{0:N1}°", gamma);

          //  coxaFemurConstraint.Transform = bodyCoxaTransform;


        }
 private Point3D GetPointAdjustedBy(Point3D point, Point3D adjustBy)
 {
     var newPoint = new Point3D { X = point.X, Y = point.Y, Z = point.Z };
     newPoint.Offset(adjustBy.X, adjustBy.Y, adjustBy.Z);
     return newPoint;
 }
示例#4
0
        /// <summary>
        /// Helper function used by <see cref="CreateControlPoints" /> to populate the data
        /// stuctures which hold control point data.
        /// </summary>
        private void PopulateControlLists()
        {
            Vector3D previousD = new Vector3D();

            for (int i = 0; i < this.caList.Count - 1; i++)
            {
                Point3D ca1 = this.caList[i];
                Point3D o1 = this.oList[i];
                Point3D ca2 = this.caList[i + 1];

                Point3D p = new Point3D((ca1.X + ca2.X) / 2, (ca1.Y + ca2.Y) / 2,
                    (ca1.Z + ca2.Z) / 2);

                Vector3D a = ca2 - ca1;
                Vector3D b = o1 - ca1;

                Vector3D c = Vector3D.CrossProduct(a, b);
                Vector3D d = Vector3D.CrossProduct(c, a);

                c.Normalize();
                d.Normalize();

                if (this.isHelixList[i] && this.isHelixList[i + 1])
                    p.Offset(1.5 * c.X, 1.5 * c.Y, 1.5 * c.Z);

                if (i > 0 && Vector3D.AngleBetween(d, previousD) > 90) d.Negate();
                previousD = d;

                this.pList.Add(p);
                this.dList.Add(p + d);
            }
        }