コード例 #1
0
        // Compute angle P1, P2, P3
        public static double ComputeAngle(Point3D p1, Point3D p2, Point3D p3)
        {
            Vector3D ab = new Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
            Vector3D bc = new Vector3D(p3.X - p2.X, p3.Y - p2.Y, p3.Z - p2.Z);

            return(Vector3D.AngleBetween(ab, bc));
        }
コード例 #2
0
        public void Look(Point currentPosition)
        {
            Vector3D currentPosition3D = ProjectToTrackball(EventSource.ActualWidth, EventSource.ActualHeight, currentPosition);
            //currentPosition3D = new Vector3D(_previousPosition3D.X, _previousPosition3D.Y, currentPosition3D.Z);
            Vector3D axis  = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D);
            double   angle = Vector3D.AngleBetween(_previousPosition3D, currentPosition3D);

            //axis.X = 0;
            //axis.Z = 0;
            //axis.Y = 0;
            if (axis.Length == 0)
            {
                _previousPosition3D = currentPosition3D;
                return;
            }

            Quaternion delta = new Quaternion(axis, -angle);

            // Get the current orientantion from the RotateTransform3D
            AxisAngleRotation3D r = _rotation;
            Quaternion          q = new Quaternion(_rotation.Axis, _rotation.Angle);

            // Compose the delta with the previous orientation
            q *= delta;

            // Write the new orientation back to the Rotation3D
            _rotation.Axis = q.Axis;
            //_rotation.Axis = new Vector3D(q.Axis.X, _rotation.Axis.Y, _rotation.Axis.Z);
            _rotation.Angle = q.Angle;

            _previousPosition3D = currentPosition3D;
        }
コード例 #3
0
        internal void Track(Point currentPosition)
        {
            var currentPosition3D = ProjectToTrackball(ActualWidth, ActualHeight, currentPosition);


            var angle = Vector3D.AngleBetween(_previousPosition3D, currentPosition3D);
            var axis  = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D);

            // quaterion will throw if this happens - sometimes we can get 3D positions that
            // are very similar, so we avoid the throw by doing this check and just ignoring
            // the event
            if (axis.Length == 0)
            {
                return;
            }

            var delta = new Quaternion(axis, -angle);
            var q     = new Quaternion(_rotation.Axis, _rotation.Angle);

            q *= delta;

            // Write the new orientation back to the Rotation3D
            _rotation.Axis      = q.Axis;
            _rotation.Angle     = q.Angle;
            _previousPosition3D = currentPosition3D;
        }
コード例 #4
0
        public Transform3D Track(Point currentPosition, double width, double height)
        {
            Vector3D currentPosition3D = ProjectToTrackball(width, height, currentPosition);

            Vector3D axis = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D);

            if (axis.Length < 100 * double.Epsilon)
            {
                return(_transform);
            }

            double angle = Vector3D.AngleBetween(_previousPosition3D, currentPosition3D);

            Quaternion delta = new Quaternion(axis, -angle);

            _orientation = new Quaternion(_rotation.Axis, _rotation.Angle);
            // Compose the delta with the previous orientation
            _orientation *= delta;

            // Write the new orientation back to the Rotation3D
            _rotation.Axis  = _orientation.Axis;
            _rotation.Angle = _orientation.Angle;

            _previousPosition3D = currentPosition3D;
            _previousPosition2D = currentPosition;
            return(_transform);
        }
コード例 #5
0
ファイル: Beam.cs プロジェクト: GoldCup42/STAADModel
        void GenerateLocalAxes()
        {
            var globalX = new Vector3D(1.0, 0.0, 0.0);

            // Get the beams orientation vector
            this.LongitudinalAxis = new Vector3D(this.EndNode.X - this.StartNode.X, this.EndNode.Y - this.StartNode.Y, this.EndNode.Z - this.StartNode.Z);

            // Compute the transformation required to match the X axis
            double angle = Vector3D.AngleBetween(this.LongitudinalAxis, globalX);

            var rotation = Quaternion.Identity;

            if (angle % 180 != 0)
            {
                rotation = new Quaternion(Vector3D.CrossProduct(globalX, this.LongitudinalAxis), angle);
            }
            else
            {
                rotation = new Quaternion(new Vector3D(0.0, 1.0, 0.0), angle);
            }

            rotation.Normalize();

            var transformation = Matrix3D.Identity;

            transformation.Rotate(rotation);

            // Apply the transformation
            this.LongitudinalAxis = transformation.Transform(globalX);
            this.MajorAxis        = transformation.Transform(new Vector3D(0.0, 0.0, 1.0));
            this.MinorAxis        = transformation.Transform(new Vector3D(0.0, 1.0, 0.0));
        }
コード例 #6
0
ファイル: Swoosher.xaml.cs プロジェクト: Shine6Z/GenXSource
        private void canvas_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown /*&& physics == null*/)
            {
                if (!mouseCaptured)
                {
                    root.CaptureMouse();
                    mouseCaptured = true;
                }

                Vector3D position = Trackball.ProjectToTrackball(Width, Height, e.GetPosition(root));

                Vector3D axis  = Vector3D.CrossProduct(anchorPosition, position);
                double   angle = Vector3D.AngleBetween(anchorPosition, position);

                if (axis != new Vector3D())
                {
                    axis.Y *= -1;
                    Quaternion delta = new Quaternion(axis, angle);

                    camera.Rotation   *= delta;
                    camera.UpDirection = camera.GetRotationMatrix().Transform(new Vector3D(0, 1, 0));
                }

                anchorPosition = position;
                needsRefresh   = true;
            }
        }
コード例 #7
0
        internal static Device CalculateClosestMatch(List <Device> devices, Point3D[] vectors)
        {
            Device currDev  = null;
            Double currDist = -1;

            if (vectors == null)
            {
                return(null);
            }

            // pointing ray goes from vectors[0] to vectors[1]
            Ray3D pointer = new Ray3D(vectors[0], vectors[1]);

            Double tempDist;

            foreach (Device dev in devices)
            {
                foreach (Ball ball in dev.Form)
                {
                    // check if Ball is in front of pointing ray
                    if (Vector3D.AngleBetween(pointer.direction, ball.Center - pointer.origin) < 90)
                    {
                        // check distance
                        tempDist = Point3D.Subtract(pointer.nearestPoint(ball.Center), ball.Center).Length;
                        if (currDist == -1 || tempDist < currDist)
                        {
                            currDev  = dev;
                            currDist = tempDist;
                        }
                    }
                }
            }

            return(currDev);
        }
コード例 #8
0
        /// <summary>
        ///    The Methode does the collision detection
        ///    First the pointing vector of the underarm is calculated.
        ///    This vector will be "extended" to a straight line. Following it will be calculated if this line hits a sphere of a device.
        ///    Hit devices will be saved in a list.
        /// </summary>
        /// <param name="devices">Devices which are available in the system</param>
        /// <param name="vectors">The position vectors of the ellbows and wrists</param>
        /// <returns>Devicelist with hit devices</returns>
        internal static List <Device> Calculate(List <Device> devices, Point3D[] vectors)
        {
            List <Device> found = new List <Device>();


            if (vectors == null)
            {
                return(found);
            }

            // pointing ray goes from vectors[0] to vectors[1]
            Ray3D pointer = new Ray3D(vectors[0], vectors[1]);

            foreach (Device dev in devices)
            {
                foreach (Ball ball in dev.Form)
                {
                    // check if Ball is in front of pointing ray
                    if (Vector3D.AngleBetween(pointer.direction, ball.Center - pointer.origin) < 90)
                    {
                        // check distance
                        if (Point3D.Subtract(pointer.nearestPoint(ball.Center), ball.Center).Length <= ball.Radius)
                        {
                            found.Add(dev);
                            continue; // skip other balls of this dev
                        }
                    }
                }
            }
            return(found);
        }
コード例 #9
0
        private void Normalize(object sender, RoutedEventArgs e)
        {
            firstVecFromUser  = goThroughText(FirstVec3X.Text, FirstVec3Y.Text, FirstVec3Z.Text);
            secondVecFromUser = goThroughText(SecondVec3X.Text, SecondVec3Y.Text, SecondVec3Z.Text);

            Vector3D.AngleBetween(firstVecFromUser, secondVecFromUser);
        }
コード例 #10
0
        /// <summary>
        /// Calculates the angle between the specified points around the specified axis.
        /// </summary>
        /// <param name="center">The center of the angle.</param>
        /// <param name="start">The start of the angle.</param>
        /// <param name="end">The end of the angle.</param>
        /// <param name="axis">The axis around which the angle is calculated.</param>
        /// <returns>The angle, in degrees.</returns>
        public static double Angle(this CameraSpacePoint center, CameraSpacePoint start, CameraSpacePoint end, Axis axis)
        {
            switch (axis)
            {
            case Axis.X:
                start.X  = 0f;
                center.X = 0f;
                end.X    = 0f;
                break;

            case Axis.Y:
                start.Y  = 0f;
                center.Y = 0f;
                end.Y    = 0f;
                break;

            case Axis.Z:
                start.Z  = 0f;
                center.Z = 0f;
                end.Z    = 0f;
                break;
            }

            Vector3D first  = start.ToVector3() - center.ToVector3();
            Vector3D second = end.ToVector3() - center.ToVector3();

            return(Vector3D.AngleBetween(first, second));
        }
コード例 #11
0
        public void ProductTest()
        {
            //
            // TODO: Add test logic	here
            //
            // Calculates the angle between two Vector3Ds using the static AngleBetween method.
            // Returns a Double.

            Vector3D vector1 = new Vector3D(20, 30, 40);
            Vector3D vector2 = new Vector3D(45, 70, 80);
            Double   angleBetween;

            angleBetween = Vector3D.AngleBetween(vector1, vector2);
            // angleBetween is approximately equal to 4.15129

            Console.WriteLine(angleBetween);
            double produect = Vector3D.DotProduct(vector1, vector2);

            Console.WriteLine(produect);
            double anglecos = Vector3D.DotProduct(vector1, vector2) / vector1.Length / vector2.Length;

            Console.WriteLine(anglecos);
            double angle = Math.Acos(Vector3D.DotProduct(vector1, vector2) / vector1.Length / vector2.Length);

            Console.WriteLine(angle);
            Console.WriteLine(angle / Math.PI * 180);
        }
コード例 #12
0
        /// <summary>
        /// Calculates the angle and updates the arc according to the specifed vectors.
        /// </summary>
        /// <param name="start">The vector of the starting point.</param>
        /// <param name="middle">The vector of the middle point.</param>
        /// <param name="end">The vector of the end point.</param>
        /// <param name="desiredRadius">The desired arc radius.</param>
        public void Update(Vector3D start, Vector3D middle, Vector3D end, double desiredRadius = 0)
        {
            _vector1 = middle - start;
            _vector2 = middle - end;

            if (desiredRadius == 0)
            {
                desiredRadius = Math.Min(_vector1.Length, _vector2.Length);
            }

            _vector1.Normalize();
            _vector2.Normalize();

            _angle = Vector3D.AngleBetween(_vector1, _vector2);

            start = middle - desiredRadius * _vector1;
            end   = middle - desiredRadius * _vector2;

            line1.Point            = middle.ToPoint();
            line2.Point            = start.ToPoint();
            angleFigure.StartPoint = end.ToPoint();

            arc.IsLargeArc = _angle > 180.0;
            arc.Point      = end.ToPoint();
            arc.Size       = new Size(desiredRadius, desiredRadius);
        }
コード例 #13
0
        public static Vector3D[] FindVectorsAtRightAnglesTo(Vector3D v)
        {
            var vectors = new List <Vector3D>();
            var n       = (int)v.Length;

            for (int x = -n; x <= n; x++)
            {
                for (int y = -n; y <= n; y++)
                {
                    for (int z = -n; z <= n; z++)
                    {
                        if (!(x == 0 && y == 0 && z == 0))
                        {
                            var vr = new Vector3D(x, y, z);
                            if (Math.Abs(vr.LengthSquared - v.LengthSquared) < 1e-9 &&
                                Math.Abs(Math.Abs(Vector3D.AngleBetween(vr, v)) - 90) < 1e-9)
                            {
                                vectors.Add(vr);
                            }
                        }
                    }
                }
            }
            return(vectors.Distinct().ToArray());
        }
コード例 #14
0
        protected double getAngle(JointObject j1, JointObject j2, JointObject j3)
        {
            Vector3D v1 = new Vector3D(j2.x - j1.x, j2.y - j1.y, j2.z - j1.z);
            Vector3D v2 = new Vector3D(j2.x - j3.x, j2.y - j3.y, j2.z - j3.z);

            return(Vector3D.AngleBetween(v1, v2));
        }
コード例 #15
0
        /// <summary>
        /// The rotate trackball.
        /// </summary>
        /// <param name="p1">
        /// The previous mouse position.
        /// </param>
        /// <param name="p2">
        /// The current mouse position.
        /// </param>
        /// <param name="rotateAround">
        /// The point to rotate around.
        /// </param>
        private void RotateTrackball(Point p1, Point p2, Point3D rotateAround)
        {
            // http://viewport3d.com/trackball.htm
            // http://www.codeplex.com/3DTools/Thread/View.aspx?ThreadId=22310
            var v1 = ProjectToTrackball(p1, this.Viewport.ActualWidth, this.Viewport.ActualHeight);
            var v2 = ProjectToTrackball(p2, this.Viewport.ActualWidth, this.Viewport.ActualHeight);

            // transform the trackball coordinates to view space
            var viewZ = this.Camera.LookDirection;
            var viewX = Vector3D.CrossProduct(this.Camera.UpDirection, viewZ);
            var viewY = Vector3D.CrossProduct(viewX, viewZ);

            viewX.Normalize();
            viewY.Normalize();
            viewZ.Normalize();
            var u1 = (viewZ * v1.Z) + (viewX * v1.X) + (viewY * v1.Y);
            var u2 = (viewZ * v2.Z) + (viewX * v2.X) + (viewY * v2.Y);

            // Could also use the Camera ViewMatrix
            // var vm = Viewport3DHelper.GetViewMatrix(this.ActualCamera);
            // vm.Invert();
            // var ct = new MatrixTransform3D(vm);
            // var u1 = ct.Transform(v1);
            // var u2 = ct.Transform(v2);

            // Find the rotation axis and angle
            var axis = Vector3D.CrossProduct(u1, u2);

            if (axis.LengthSquared < 1e-8)
            {
                return;
            }

            double angle = Vector3D.AngleBetween(u1, u2);

            // Create the transform
            var delta  = new Quaternion(axis, -angle * this.RotationSensitivity * 5);
            var rotate = new RotateTransform3D(new QuaternionRotation3D(delta));

            // Find vectors relative to the rotate-around point
            var relativeTarget   = rotateAround - this.Camera.Target;
            var relativePosition = rotateAround - this.Camera.Position;

            // Rotate the relative vectors
            var newRelativeTarget   = rotate.Transform(relativeTarget);
            var newRelativePosition = rotate.Transform(relativePosition);
            var newUpDirection      = rotate.Transform(this.Camera.UpDirection);

            // Find new camera position
            var newTarget   = rotateAround - newRelativeTarget;
            var newPosition = rotateAround - newRelativePosition;

            this.Camera.LookDirection = newTarget - newPosition;
            if (this.CameraMode == CameraMode.Inspect)
            {
                this.Camera.Position = newPosition;
            }

            this.Camera.UpDirection = newUpDirection;
        }
コード例 #16
0
        public static double GetRotationXZ(this Matrix3D matrix, double rotationZ)
        {
            // back off z rotation
            Matrix3D matrix2 = new Matrix3D();

            matrix2.Append(matrix);
            matrix2 = matrix2.RotateXYZ(new Vector3D(0.0, 0.0, rotationZ * -1.0));

            Vector3D localX = matrix2.Transform(new Vector3D(1, 0, 0));
            Vector3D localY = matrix2.Transform(new Vector3D(0, 1, 0));

            // rotation about the X axis
            localY.X = 0.0;
            double angle     = Vector3D.AngleBetween(localY, new Vector3D(0, 1, 0));
            double rotationX = localX.Z > 0 ? angle * -1.0 : angle;

            if (Abs(rotationX - 180.0) > 0.01 && Abs(localY.Z) < 0.0001)
            {
                rotationX = 0.0;
            }

            if (Abs(localY.Y + 1.0) < 0.01)
            {
                rotationX = 0.0;
            }

            return(rotationX);
        }
コード例 #17
0
ファイル: MainWindow.xaml.cs プロジェクト: nsmela/Fabolus
        private MeshGeometry3D ShowSteepAngles(double angle, Vector3D reference, bool inverted)
        {
            //to store the outgoing mesh
            var            mesh        = new MeshBuilder(true);
            MeshGeometry3D scannedMesh = bolus.Mesh();

            //calculate for each triangle
            for (int triangle = 0; triangle < scannedMesh.TriangleIndices.Count; triangle += 3)
            {
                //get the triangle's normal
                int i0 = scannedMesh.TriangleIndices[triangle];
                int i1 = scannedMesh.TriangleIndices[triangle + 1];
                int i2 = scannedMesh.TriangleIndices[triangle + 2];

                Point3D p0 = scannedMesh.Positions[i0];
                Point3D p1 = scannedMesh.Positions[i1];
                Point3D p2 = scannedMesh.Positions[i2];

                var normal = CalculateSurfaceNormal(p0, p1, p2);

                //calculate normal's angle from the ground
                //using the z-axis as to determine how the angle if from the ground
                var degrees = Vector3D.AngleBetween(normal, reference);

                //if angle less than steepangle, add the triangle to the overhang mesh
                if (degrees < angle)
                {
                    mesh.AddTriangle(p0, p1, p2);
                }
            }

            return(mesh.ToMesh());
        }
コード例 #18
0
        /// <summary>
        /// Calculates the angle between the specified points.
        /// </summary>
        /// <param name="center">The center of the angle.</param>
        /// <param name="start">The start of the angle.</param>
        /// <param name="end">The end of the angle.</param>
        /// <returns>The angle, in degrees.</returns>
        public static double AngleBetween(this DepthSpacePoint center, DepthSpacePoint start, DepthSpacePoint end)
        {
            Vector3D first  = start.ToVector3() - center.ToVector3();
            Vector3D second = end.ToVector3() - center.ToVector3();

            return(Vector3D.AngleBetween(first, second));
        }
コード例 #19
0
        public bool IsVisible(double cameraZ)
        {
            var camFaceCenterVector = new Vector3D(-_center.X, -_center.Y, -cameraZ - _center.Z);
            var angle = Vector3D.AngleBetween(camFaceCenterVector, _faceFront);

            return(angle < 90.0);
        }
コード例 #20
0
        private void Track(Point currentPosition)
        {
            Vector3D currentPosition3D = ProjectToTrackball(
                ActualWidth, ActualHeight, currentPosition);

            Vector3D axis  = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D);
            double   angle = Vector3D.AngleBetween(_previousPosition3D, currentPosition3D);

            // quaterion will throw if this happens - sometimes we can get 3D positions that
            // are very similar, so we avoid the throw by doing this check and just ignoring
            // the event
            if (axis.Length == 0)
            {
                return;
            }

            Quaternion delta = new Quaternion(axis, -angle);

            // Get the current orientantion from the RotateTransform3D
            AxisAngleRotation3D r = _rotation;
            Quaternion          q = new Quaternion(_rotation.Axis, _rotation.Angle);

            // Compose the delta with the previous orientation
            q *= delta;

            // Write the new orientation back to the Rotation3D
            _rotation.Axis  = q.Axis;
            _rotation.Angle = q.Angle;

            _previousPosition3D = currentPosition3D;
        }
コード例 #21
0
        static void Main(string[] args)
        {
            Vector3D u = new Vector3D(0, 3, 4);
            Vector3D v = new Vector3D(0, 4, -3);
            Point3D  a = new Point3D(10, 12, 15);
            Point3D  b = a + u;     // Point + Vector = Point
            Vector3D w = b - a;     // Point - Point = Vector
            Vector3D t = u + v;     // Vector + Vector = Vector

            double   angle = Vector3D.AngleBetween(u, v);
            Vector3D cross = Vector3D.CrossProduct(u, v);
            double   dot   = Vector3D.DotProduct(u, v);

            Vector3D normal = cross;

            normal.Normalize();
            Vector3D scaled = normal * 10;

            Console.WriteLine("u:\t" + u.ToString());
            Console.WriteLine("v:\t" + v.ToString());
            Console.WriteLine("w:\t" + w.ToString());
            Console.WriteLine("a:\t" + a.ToString());
            Console.WriteLine("b:\t" + b.ToString());
            Console.WriteLine("angle:\t" + angle.ToString());
            Console.WriteLine("cross:\t" + cross.ToString());
            Console.WriteLine("dot:\t" + dot.ToString());
            Console.WriteLine("normal:\t" + normal.ToString());
            Console.WriteLine("scaled:\t" + scaled.ToString());
            Console.ReadLine();
        }
コード例 #22
0
        /// <summary>
        /// Calculates the angle between the specified points.
        /// </summary>
        /// <param name="center">The center of the angle.</param>
        /// <param name="start">The start of the angle.</param>
        /// <param name="end">The end of the angle.</param>
        /// <returns>The angle, in degrees.</returns>
        public static double Angle(this CameraSpacePoint center, CameraSpacePoint start, CameraSpacePoint end)
        {
            Vector3D first  = new Vector3D(start.X, start.Y, start.Z) - new Vector3D(center.X, center.Y, center.Z);
            Vector3D second = new Vector3D(end.X, end.Y, end.Z) - new Vector3D(center.X, center.Y, center.Z);

            return(Vector3D.AngleBetween(first, second));
        }
コード例 #23
0
        // Make a cylinder using vectors perpendicular to the axis.
        private void MakeCylinder(Model3DGroup model_group, ref MeshGeometry3D cylinder_mesh,
                                  Material cylinder_material,
                                  double cx1, double cy1, double cz1,
                                  double cx2, double cy2, double cz2,
                                  double uv1, double uv2, double uv3, double uv4,
                                  double radius1, double radius2, int num_theta)
        {
            // Get the axis.
            Vector3D axis = new Vector3D(cx2 - cx1, cy2 - cy1, cz2 - cz1);

            // Just pick a vector to start from.
            Vector3D vector1 = new Vector3D(1, 0, 0);

            if (Vector3D.AngleBetween(axis, vector1) < 0.1) // See if they're parallel.
            {
                // Pick a different vector1.
                vector1 = new Vector3D(0, 0, 1);
            }

            // Find perpendicular vectors.
            Vector3D vector2 = Vector3D.CrossProduct(axis, vector1);

            vector1 = Vector3D.CrossProduct(axis, vector2);
            vector1.Normalize();
            vector2.Normalize();

            // Make the cylinder.
            MakeCylinder(model_group, ref cylinder_mesh, cylinder_material,
                         cx1, cy1, cz1, cx2, cy2, cz2, uv1, uv2, uv3, uv4,
                         radius1, radius2, num_theta, vector1, vector2);
        }
コード例 #24
0
ファイル: Trackball.cs プロジェクト: bondehagen/meshellator
        private void Track(Point currentPosition)
        {
            Vector3D currentPosition3D = ProjectToTrackball(EventSource.ActualWidth, EventSource.ActualHeight, currentPosition);

            IoC.Get <IOutput>().Append("New trackball position: " + currentPosition3D);

            // Because our sphere is centered at the origin, we may interpret our points as vectors. Doing so it is trivial
            // to find the axis and angle of rotation using the cross product dot product respectively.
            Vector3D axis  = Vector3D.Cross(_initialPosition3D, currentPosition3D);
            float    angle = Vector3D.AngleBetween(_initialPosition3D, currentPosition3D);

            // We negate the angle because we are rotating the camera (if we were rotating the scene, we wouldn't do this).
            Quaternion delta = new Quaternion(axis, -angle);

            // Get the initial orientation.
            Quaternion q = _persistentOrientation;

            // Compose the delta with the previous orientation
            q *= delta;

            // Store the new orientation.
            _rotation.Axis  = q.Axis;
            _rotation.Angle = q.Angle;

            _currentOrientation = q;

            //_previousPosition3D = currentPosition3D;
        }
コード例 #25
0
ファイル: 3DController.xaml.cs プロジェクト: wangdi190/DNV863
        Point3D panelCenter = new Point3D(0, 0, 0);  //控制板操作状态的中心点


        /// <summary>
        /// 获取屏幕点与地平面Y=0的交点
        /// </summary>
        /// <param name="p">viewport3D上的屏幕点</param>
        private void getCrossPoint3D(Point p)
        {
            Matrix3D matrix2, matrixc;
            Vector3D v1, v2;
            Vector3D raxis; double rangle;
            //v1 = new Vector3D(0, 0, -1);
            PerspectiveCamera camera = mainViewport3D.Camera as PerspectiveCamera;

            matrixc = (camera.Transform as MatrixTransform3D).Matrix;

            Point3D pline = camera.Position;

            pline = matrixc.Transform(pline);
            Vector3D vline = camera.LookDirection;

            vline = matrixc.Transform(vline);
            double angx = Math.Atan((p.X - mainViewport3D.ActualWidth / 2) / (mainViewport3D.ActualWidth / 2) * Math.Tan(camera.FieldOfView / 2 / 180 * Math.PI));
            double angy = Math.Atan((-p.Y + mainViewport3D.ActualHeight / 2) / (mainViewport3D.ActualWidth / 2) * Math.Tan(camera.FieldOfView / 2 / 180 * Math.PI));

            v1    = new Vector3D(0, 0, -1);
            v2    = new Vector3D(Math.Tan(angx), Math.Tan(angy), -1);
            raxis = Vector3D.CrossProduct(v1, v2);
            raxis.Normalize();
            raxis = matrixc.Transform(raxis);
            raxis.Normalize();
            rangle = Vector3D.AngleBetween(v1, v2);
            if (rangle != 0)
            {
                matrix2 = new Matrix3D();
                matrix2.Rotate(new Quaternion(raxis, rangle));
                vline = matrix2.Transform(vline);
                vline.Normalize();
            }
            _pcenter = Model3DHelper.calFlatXLine(new Vector3D(0, 1, 0), new Point3D(10000, 0, 10000), vline, pline);
        }
コード例 #26
0
        private void Track(Point currentPosition)
        {
            try
            {
                Vector3D currentPosition3D = ProjectToTrackball(
                    EventSource.ActualWidth, EventSource.ActualHeight, currentPosition);

                Vector3D   axis  = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D);
                double     angle = Vector3D.AngleBetween(_previousPosition3D, currentPosition3D);
                Quaternion delta = new Quaternion(axis, -angle);

                AxisAngleRotation3D r = _rotation;
                Quaternion          q = new Quaternion(_rotation.Axis, _rotation.Angle);

                q *= delta;

                _rotation.Axis  = q.Axis;
                _rotation.Angle = q.Angle;

                _previousPosition3D = currentPosition3D;
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Exception while tracking movement: " + ex);
            }
        }
コード例 #27
0
            public void getTiltsbyAA_divided(Vector3D axis, int strandNum, ref Dictionary <string, AminoAcid> _aaDict)
            {
                if (this.StrandNum % 2 == 0)
                {// calculate tilt
                    for (int resCtr = 0; resCtr < this.Residues.Count; resCtr++)
                    {
                        if (resCtr > 0 && resCtr < this.Residues.Count - 1 && _aaDict.ContainsKey(this.Residues[resCtr].ThreeLetCode))
                        {
                            _aaDict[this.Residues[resCtr].ThreeLetCode].Tilt_even.Add(Vector3D.AngleBetween(this.Residues[resCtr - 1].BackboneCoords["CA"] - this.Residues[resCtr + 1].BackboneCoords["CA"], axis));
                            this.AvgTilt_even += (Vector3D.AngleBetween(this.Residues[resCtr - 1].BackboneCoords["CA"] - this.Residues[resCtr + 1].BackboneCoords["CA"], axis) / (this.Residues.Count - 2));
                        }
                    }
                }

                else // if odd
                {
                    for (int resCtr = 0; resCtr < this.Residues.Count; resCtr++)
                    {
                        if (resCtr > 0 && resCtr < this.Residues.Count - 1 && _aaDict.ContainsKey(this.Residues[resCtr].ThreeLetCode))
                        {
                            _aaDict[this.Residues[resCtr].ThreeLetCode].Tilt_odd.Add(Vector3D.AngleBetween(this.Residues[resCtr - 1].BackboneCoords["CA"] - this.Residues[resCtr + 1].BackboneCoords["CA"], axis));
                            this.AvgTilt_odd += (Vector3D.AngleBetween(this.Residues[resCtr - 1].BackboneCoords["CA"] - this.Residues[resCtr + 1].BackboneCoords["CA"], axis) / (this.Residues.Count - 2));
                        }
                    }
                }
            }
コード例 #28
0
ファイル: Trackball.cs プロジェクト: nbright/Diplomarbeit
        /// <summary>
        ///
        /// </summary>
        private void Look(Point currentPosition)
        {
            Vector3D currentPosition3D = ProjectToTrackball(
                EventSource.ActualWidth, EventSource.ActualHeight, currentPosition);

            if (_previousPosition3D.Equals(currentPosition3D))
            {
                return;
            }

            Vector3D axis = Vector3D.CrossProduct(_previousPosition3D, currentPosition3D);

            double     angle = _rotationFactor * Vector3D.AngleBetween(_previousPosition3D, currentPosition3D);
            Quaternion delta = new Quaternion(axis, -angle);

            // Get the current orientation from the RotateTransform3D
            AxisAngleRotation3D r = _rotation;
            Quaternion          q = new Quaternion(_rotation.Axis, _rotation.Angle);

            // Compose the delta with the previous orientation
            q *= delta;

            // Write the new orientation back to the Rotation3D
            _rotation.Axis  = q.Axis;
            _rotation.Angle = q.Angle;

            _previousPosition3D = currentPosition3D;
        }
コード例 #29
0
        public static double AngleBetweenThreePoints(SolidEdgeGeometry.Vertex Start, SolidEdgeGeometry.Vertex Center, SolidEdgeGeometry.Vertex End)//, Vector3D up)
        {
            //Vertexs.GetPointData

            Array p1 = Array.CreateInstance(typeof(double), 0);
            Array p2 = Array.CreateInstance(typeof(double), 0);
            Array p3 = Array.CreateInstance(typeof(double), 0);

            double[] pointStart;
            double[] pointCenter;
            double[] pointEnd;

            Start.GetPointData(ref p1);
            Center.GetPointData(ref p2);
            End.GetPointData(ref p3);

            pointStart  = (double[])p1;
            pointCenter = (double[])p2;
            pointEnd    = (double[])p3;

            double x1 = 0 - pointCenter[0];
            double y1 = 0 - pointCenter[1];
            double z1 = 0 - pointCenter[2];

            Vector3D vt1 = new Vector3D(pointStart[0] + x1, pointStart[1] + y1, pointStart[2] + z1);
            Vector3D vt3 = new Vector3D(pointEnd[0] + x1, pointEnd[1] + y1, pointEnd[2] + z1);

            return(Math.Round(Vector3D.AngleBetween(vt1, vt3)));
        }
コード例 #30
0
        private void Sphere_MouseMove(object sender, MouseEventArgs e)
        {
            if (_isMouseLeftButtonDown)
            {
                Visual3DHitTestHelper visual3DHitTestHelper = new Visual3DHitTestHelper();
                visual3DHitTestHelper.HitTest(Viewport3D, _mousePosition, out Visual3D hitVisual3D, out Point3D HitPoint3D);

                Point mousePotion = e.GetPosition(null);
                visual3DHitTestHelper.HitTest(Viewport3D, mousePotion, out Visual3D hitVisual3D1, out Point3D HitPoint3D1);

                Vector3D vector1 = new Vector3D(HitPoint3D.X, HitPoint3D.Y, HitPoint3D.Z);
                Vector3D vector2 = new Vector3D(HitPoint3D1.X, HitPoint3D1.Y, HitPoint3D1.Z);

                Vector3D rotateAxis            = Vector3D.CrossProduct(vector1, vector2);
                double   horizontalRotateAngle = -Vector3D.AngleBetween(vector1, vector2);

                Camera?.RotateAroundAxis(rotateAxis, horizontalRotateAngle);
                _mousePosition = e.GetPosition(null);

                _isCameraRotated = true;

                RoutedEventArgs args = new RoutedEventArgs(CameraStatusChangingEvent, this);
                RaiseEvent(args);
            }
        }
コード例 #31
0
ファイル: Ellipsoid.cs プロジェクト: jpespartero/OpenGlobe
        public IList<Vector3D> ComputeCurve(
            Vector3D start, 
            Vector3D stop, 
            double granularity)
        {
            if (granularity <= 0.0)
            {
                throw new ArgumentOutOfRangeException("granularity", "Granularity must be greater than zero.");
            }

            Vector3D normal = start.Cross(stop).Normalize();
            double theta = start.AngleBetween(stop);
            int n = Math.Max((int)(theta / granularity) - 1, 0);
            
            List<Vector3D> positions = new List<Vector3D>(2 + n);

            positions.Add(start);

            for (int i = 1; i <= n; ++i)
            {
                double phi = (i * granularity);

                positions.Add(ScaleToGeocentricSurface(start.RotateAroundAxis(normal, phi)));
            }

            positions.Add(stop);

            return positions;
        }