コード例 #1
0
        private Point3D[,] Redraw(string nodename)
        {
            var data = new Point3D[model.Rows + 1, model.Columns + 1];
            var dataOriginal = new Point4D[model.Rows + 1, model.Columns + 1];
            MathNet.Numerics.Complex32 W;
            for (int i = 0; i <= model.Rows; i++)
                for (int j = 0; j <= model.Columns; j++)
                {
                    W = sol1.WfromIndexes[new Tuple<int, int>(i, j)];
                    foreach (var node in sol1.Voltages[W])
                    {
                        if (node.Key == nodename)
                        {
                            data[i, j] = new Point3D(W.Real,
                                                    W.Imaginary,
                                //node.Value.Magnitude);
                                                    Math.Log10(node.Value.Magnitude));
                            dataOriginal[i, j] = new Point4D(W.Real, W.Imaginary,
                                                            node.Value.Magnitude, node.Value.Phase);

                        }
                    }
                }
            surface.OriginalData = dataOriginal;
            model.Data = data;
            model.UpdateModel(false);

            return data;
        }
コード例 #2
0
 public NewtonVector4(Point4D vector)
 {
     this.Vector[0] = (float)vector.X;
     this.Vector[1] = (float)vector.Y;
     this.Vector[2] = (float)vector.Z;
     this.Vector[3] = (float)vector.W;
 }
コード例 #3
0
		public NewtonVector4(Point4D pVector)
		{
			NWVector4[ 0 ] = (float)pVector.X;
			NWVector4[ 1 ] = (float)pVector.Y;
			NWVector4[ 2 ] = (float)pVector.Z;
			NWVector4[ 3 ] = (float)pVector.W;
		}
コード例 #4
0
		public object m_UserData;			// user data passed to the collision geometry at creation time

		internal UserMeshCollisionRayHitDesc(Newton.NewtonUserMeshCollisionRayHitDesc pRayHitDesc)
		{
			m_NormalOut = new NewtonVector4(pRayHitDesc.m_NormalOut).ToDirectX();
			m_P0 = new NewtonVector4(pRayHitDesc.m_P0).ToDirectX();
			m_P1 = new NewtonVector4(pRayHitDesc.m_P1).ToDirectX();
			m_UserData = CHashTables.BodyUserData[pRayHitDesc.m_UserData];
			m_UserIdOut = pRayHitDesc.m_UserIdOut;
		}
コード例 #5
0
		public Point4D ToDirectX()
		{
			Point4D aDXVecor = new Point4D();

			aDXVecor.X = NWVector4[0];
			aDXVecor.Y = NWVector4[1];
			aDXVecor.Z = NWVector4[2];
			aDXVecor.W = NWVector4[3];

			return aDXVecor;
		}
コード例 #6
0
        // Displays the values of the variables
        public void ShowVars()
        {
            Point4D p1 = new Point4D(10, 5, 1, 4);
            Point4D p2 = new Point4D(15, 40, 60, 75);

            Matrix3D m1 = new Matrix3D(10,10,10,0,20,20,20,0,30,30,30,0,5,10,15,1);

            // Displaying values in Text objects
            txtPoint1.Text = p1.ToString();
            txtPoint2.Text = p2.ToString();
            txtMatrix1.Text = m1.ToString();
        }
コード例 #7
0
		public CBody m_PolySoupBody;          	// pointer to the rigid body owner of this collision tree 

		internal UserMeshCollisionCollideDesc(Newton.NewtonUserMeshCollisionCollideDesc pDesc)
		{
			m_BoxP0 = new NewtonVector4(pDesc.m_BoxP0).ToDirectX();
			m_BoxP1 = new NewtonVector4(pDesc.m_BoxP1).ToDirectX();
			m_UserData = pDesc.m_UserData;
			m_FaceCount = pDesc.m_FaceCount;
			m_Vertex = pDesc.m_Vertex;
			m_VertexStrideInBytes = pDesc.m_VertexStrideInBytes;
			m_UserAttribute = pDesc.m_UserAttribute;
			m_FaceIndexCount = pDesc.m_FaceIndexCount;
			m_FaceVertexIndex = pDesc.m_FaceVertexIndex;
			m_ObjBody =  (CBody)CHashTables.Body[pDesc.m_ObjBody];
			m_PolySoupBody = (CBody)CHashTables.Body[pDesc.m_PolySoupBody];
		}
コード例 #8
0
        /// <summary>
        /// Gets the billboard positions with the current screen transform.
        /// </summary>
        /// <param name="billboards">The billboards.</param>
        /// <param name="offset">The offset.</param>
        /// <returns>The positions.</returns>
        public Point3DCollection GetPositions(IList<Billboard> billboards, Vector offset)
        {
            var positions = new Point3DCollection(billboards.Count * 4);

            foreach (var bb in billboards)
            {
                Point4D screenPoint;
                if (!bb.WorldDepthOffset.Equals(0))
                {
                    var viewPoint = (Point4D)bb.Position * this.visualToProjection;
                    screenPoint = new Point4D(viewPoint.X, viewPoint.Y, viewPoint.Z + bb.WorldDepthOffset, viewPoint.W) * this.projectionToScreen;
                }
                else
                {
                    screenPoint = (Point4D)bb.Position * this.visualToScreen;
                }

                double spw = screenPoint.W;
                double spx = screenPoint.X;
                double spy = screenPoint.Y;
                double spz = screenPoint.Z - (bb.DepthOffset * spw);

                // Convert bottom-left corner to visual space
                var p = new Point4D(spx + ((bb.Left + offset.X) * spw), spy + ((bb.Bottom + offset.Y) * spw), spz, spw) * this.screenToVisual;
                double wi = 1 / p.W;
                positions.Add(new Point3D(p.X * wi, p.Y * wi, p.Z * wi));

                // Convert bottom-right corner to visual space
                p = new Point4D(spx + ((bb.Right + offset.X) * spw), spy + ((bb.Bottom + offset.Y) * spw), spz, spw) * this.screenToVisual;
                wi = 1 / p.W;
                positions.Add(new Point3D(p.X * wi, p.Y * wi, p.Z * wi));

                // Convert top-right corner to visual space
                p = new Point4D(spx + ((bb.Right + offset.X) * spw), spy + ((bb.Top + offset.Y) * spw), spz, spw) * this.screenToVisual;
                wi = 1 / p.W;
                positions.Add(new Point3D(p.X * wi, p.Y * wi, p.Z * wi));

                // Convert top-left corner to visual space
                p = new Point4D(spx + ((bb.Left + offset.X) * spw), spy + ((bb.Top + offset.Y) * spw), spz, spw) * this.screenToVisual;
                wi = 1 / p.W;
                positions.Add(new Point3D(p.X * wi, p.Y * wi, p.Z * wi));
            }

            positions.Freeze();
            return positions;
        }
コード例 #9
0
ファイル: Point4DConverter.cs プロジェクト: dox0/DotNet471RS3
        /// <summary>
        /// ConvertTo - Attempt to convert an instance of Point4D to the given type
        /// </summary>
        /// <returns>
        /// The object which was constructoed.
        /// </returns>
        /// <exception cref="NotSupportedException">
        /// A NotSupportedException is thrown if "value" is null or not an instance of Point4D,
        /// or if the destinationType isn't one of the valid destination types.
        /// </exception>
        /// <param name="context"> The ITypeDescriptorContext for this call. </param>
        /// <param name="culture"> The CultureInfo which is respected when converting. </param>
        /// <param name="value"> The object to convert to an instance of "destinationType". </param>
        /// <param name="destinationType"> The type to which this will convert the Point4D instance. </param>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType != null && value is Point4D)
            {
                Point4D instance = (Point4D)value;

                if (destinationType == typeof(string))
                {
                    // Delegate to the formatting/culture-aware ConvertToString method.

                    #pragma warning suppress 6506 // instance is obviously not null
                    return(instance.ConvertToString(null, culture));
                }
            }

            // Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.)
            return(base.ConvertTo(context, culture, value, destinationType));
        }
コード例 #10
0
        internal Point WorldToViewport(Point4D point)
        {
            double aspectRatio = M3DUtil.GetAspectRatio(Viewport.Size);
            Camera camera      = Camera;

            if (camera != null)
            {
                Matrix3D viewProjMatrix = camera.GetViewMatrix() * camera.GetProjectionMatrix(aspectRatio);
                point *= viewProjMatrix;

                Point point2D = new Point(point.X / point.W, point.Y / point.W);
                point2D *= M3DUtil.GetHomogeneousToViewportTransform(Viewport);

                return(point2D);
            }
            else
            {
                return(new Point(0, 0));
            }
        }
コード例 #11
0
ファイル: Point4D.cs プロジェクト: dox0/DotNet471RS3
        /// <summary>
        /// Parse - returns an instance converted from the provided string using
        /// the culture "en-US"
        /// <param name="source"> string with Point4D data </param>
        /// </summary>
        public static Point4D Parse(string source)
        {
            IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;

            TokenizerHelper th = new TokenizerHelper(source, formatProvider);

            Point4D value;

            String firstToken = th.NextTokenRequired();

            value = new Point4D(
                Convert.ToDouble(firstToken, formatProvider),
                Convert.ToDouble(th.NextTokenRequired(), formatProvider),
                Convert.ToDouble(th.NextTokenRequired(), formatProvider),
                Convert.ToDouble(th.NextTokenRequired(), formatProvider));

            // There should be no more tokens in this string.
            th.LastTokenRequired();

            return(value);
        }
コード例 #12
0
        /// <summary>
        /// Gets the billboard positions with the current screen transform.
        /// </summary>
        /// <returns>The positions.</returns>
        public Point3DCollection GetPositions(IList<Billboard> billboards)
        {
            var positions = new Point3DCollection(billboards.Count * 4);
            foreach (var bb in billboards)
            {
                var screenPoint = (Point4D)bb.Position * this.visualToScreen;

                double spx = screenPoint.X;
                double spy = screenPoint.Y;
                double spz = screenPoint.Z;
                double spw = screenPoint.W;

                if (!bb.DepthOffset.Equals(0))
                {
                    spz -= bb.DepthOffset * spw;
                }

                var p0 = new Point4D(spx, spy, spz, spw) * this.screenToVisual;
                double pwinverse = 1 / p0.W;

                var p1 = new Point4D(spx + bb.Left * spw, spy + bb.Bottom * spw, spz, spw) * this.screenToVisual;
                positions.Add(new Point3D(p1.X * pwinverse, p1.Y * pwinverse, p1.Z * pwinverse));

                var p2 = new Point4D(spx + bb.Right * spw, spy + bb.Bottom * spw, spz, spw) * this.screenToVisual;
                positions.Add(new Point3D(p2.X * pwinverse, p2.Y * pwinverse, p2.Z * pwinverse));

                var p3 = new Point4D(spx + bb.Right * spw, spy + bb.Top * spw, spz, spw) * this.screenToVisual;
                positions.Add(new Point3D(p3.X * pwinverse, p3.Y * pwinverse, p3.Z * pwinverse));

                var p4 = new Point4D(spx + bb.Left * spw, spy + bb.Top * spw, spz, spw) * this.screenToVisual;
                positions.Add(new Point3D(p4.X * pwinverse, p4.Y * pwinverse, p4.Z * pwinverse));
            }

            positions.Freeze();
            return positions;
        }
コード例 #13
0
      // updates the matrices and plane equation and sends it to the pixel shader.</summary>
      private void _updateMatricesAndShaderValues() {
         // Creating the worldViewProj matrix corresponding to the current plane transformation
         _worldViewProj = PlaneTransformation * _viewProjMatrix;
         if (RecenterViewport) {
            Point3D transformedCenter = _worldViewProj.Transform(new Point3D(0, 0, 0));
            ViewportOffset = new Point(transformedCenter.X, transformedCenter.Y);
            _hitTestingTransform.ViewportOffset = ViewportOffset;
         }
         _worldViewProjI = _worldViewProj;
         // and its inversed matrix
         _worldViewProjI.Invert();
         _hitTestingTransform.PlaneTransformation = _worldViewProj;
         _hitTestingTransform.InverseTransformation = _worldViewProjI;


         // Calculate the 3 coordinates of the plane after transformation
         var rawTopLeft = _worldViewProj.Transform(new Point3D(-1, 1, 0));
         var rawTopRight = _worldViewProj.Transform(new Point3D(1, 1, 0));
         var rawBottomLeft = _worldViewProj.Transform(new Point3D(-1, -1, 0));

         // compute the normal of the plane
         var planeNormal = Vector3D.CrossProduct((rawTopRight - rawTopLeft), (rawBottomLeft - rawTopLeft));
         planeNormal.Normalize();

         PlaneNormal = planeNormal;
         _hitTestingTransform.PlaneNormal = planeNormal;

         // and its distance from the origin
         this.PlaneDistance = -Vector3D.DotProduct(planeNormal, new Vector3D(rawTopLeft.X, rawTopLeft.Y, rawTopLeft.Z));
         _hitTestingTransform.PlaneDistance = this.PlaneDistance;

         // Pass it to the pixel shader
         M1 = new Point4D(_worldViewProjI.M11, _worldViewProjI.M12, _worldViewProjI.M13, _worldViewProjI.M14);
         M2 = new Point4D(_worldViewProjI.M21, _worldViewProjI.M22, _worldViewProjI.M23, _worldViewProjI.M24);
         M3 = new Point4D(_worldViewProjI.M31, _worldViewProjI.M32, _worldViewProjI.M33, _worldViewProjI.M34);
         M4 = new Point4D(_worldViewProjI.OffsetX, _worldViewProjI.OffsetY, _worldViewProjI.OffsetZ, _worldViewProjI.M44);
      }
コード例 #14
0
ファイル: Point4D.cs プロジェクト: dox0/DotNet471RS3
 /// <summary>
 /// Equals - compares this Point4D with the passed in object.  In this equality
 /// Double.NaN is equal to itself, unlike in numeric equality.
 /// Note that double values can acquire error when operated upon, such that
 /// an exact comparison between two values which
 /// are logically equal may fail.
 /// </summary>
 /// <returns>
 /// bool - true if "value" is equal to "this".
 /// </returns>
 /// <param name='value'>The Point4D to compare to "this"</param>
 public bool Equals(Point4D value)
 {
     return(Point4D.Equals(this, value));
 }
コード例 #15
0
        internal override RayHitTestParameters RayFromViewportPoint(Point p, Size viewSize, Rect3D boundingRect, out double distanceAdjustment)
        {
            //
            //  Compute rayParameters
            //
            
            // Find the point on the projection plane in post-projective space where
            // the viewport maps to a 2x2 square from (-1,1)-(1,-1).
            Point np = M3DUtil.GetNormalizedPoint(p, viewSize);

            // 

            
            // So (conceptually) the user clicked on the point (np.X,
            // np.Y, 0) in post-projection clipping space and the ray
            // extends in the direction (0, 0, 1) because our ray
            // after projection looks down the positive z axis.  We
            // need to convert this ray and direction back to world
            // space.

            Matrix3D worldToCamera = GetViewMatrix() * ProjectionMatrix;
            Matrix3D cameraToWorld = worldToCamera;

            if (!cameraToWorld.HasInverse)
            {
                // 




                // NTRAID#Longhorn-1180933-2004/07/30-danwo - Need to handle singular matrix cameras
                throw new NotSupportedException(SR.Get(SRID.HitTest_Singular));
            }
            
            cameraToWorld.Invert();

            Point4D origin4D = new Point4D(np.X,np.Y,0,1) * cameraToWorld;
            Point3D origin = new Point3D( origin4D.X/origin4D.W,
                                          origin4D.Y/origin4D.W,
                                          origin4D.Z/origin4D.W );

            // To transform the direction we use the Jacobian of
            // cameraToWorld at the point np.X,np.Y,0 that we just
            // transformed.
            //
            // The Jacobian of the homogeneous matrix M is a 3x3 matrix.
            //
            // Let x be the point we are computing the Jacobian at, and y be the
            // result of transforming x by M, i.e.
            // (wy w) = (x 1) M
            // Where (wy w) is the homogeneous point representing y with w as its homogeneous coordinate
            // And (x 1) is the homogeneous point representing x with 1 as its homogeneous coordinate
            //
            // Then the i,j component of the Jacobian (at x) is
            // (M_ij - M_i4 y_j) / w
            //
            // Since we're only concerned with the direction of the
            // transformed vector and not its magnitude, we can scale
            // this matrix by a POSITIVE factor.  The computation
            // below computes the Jacobian scaled by 1/w and then
            // after we normalize the final vector we flip it around
            // if w is negative.
            //
            // To transform a vector we just right multiply it by this Jacobian matrix.
            //
            // Compute the Jacobian at np.X,np.Y,0 ignoring the constant factor of w.
            // Here's the pattern
            //
            // double Jij = cameraToWorld.Mij - cameraToWorld.Mi4 * origin.j
            //
            // but we only need J31,J32,&J33 because we're only
            // transforming the vector 0,0,1

            double J31 = cameraToWorld.M31 - cameraToWorld.M34 * origin.X;
            double J32 = cameraToWorld.M32 - cameraToWorld.M34 * origin.Y;
            double J33 = cameraToWorld.M33 - cameraToWorld.M34 * origin.Z;

            // Then multiply that matrix by (0, 0, 1) which is
            // the direction of the ray in post-projection space.
            Vector3D direction = new Vector3D( J31, J32, J33 );
            direction.Normalize();

            // We multiplied by the Jacobian times W, so we need to
            // account for whether that flipped our result or not.
            if (origin4D.W < 0)
            {
                direction = -direction;
            }
            
            RayHitTestParameters rayParameters = new RayHitTestParameters(origin, direction);

            //
            //  Compute HitTestProjectionMatrix
            //

            // The viewportMatrix will take normalized clip space into
            // viewport coordinates, with an additional 2D translation
            // to put the ray at the origin.
            Matrix3D viewportMatrix = new Matrix3D();
            viewportMatrix.TranslatePrepend(new Vector3D(-p.X,viewSize.Height-p.Y,0));
            viewportMatrix.ScalePrepend(new Vector3D(viewSize.Width/2,-viewSize.Height/2,1));
            viewportMatrix.TranslatePrepend(new Vector3D(1,1,0));
            
            // `First world-to-camera, then camera's projection, then normalized clip space to viewport.
            rayParameters.HitTestProjectionMatrix = 
                worldToCamera *
                viewportMatrix;

            // 
            // MatrixCamera does not allow for Near/Far plane adjustment, so
            // the distanceAdjustment remains 0.
            //
            distanceAdjustment = 0.0;

            return rayParameters;
        }
コード例 #16
0
ファイル: Point4D.cs プロジェクト: JianwenSun/cc
 /// <summary>
 /// Point4D * Matrix3D multiplication.
 /// </summary>
 /// <param name="point">Point being transformed.</param>
 /// <param name="matrix">Transformation matrix applied to the point.</param>
 /// <returns>Result of the transformation matrix applied to the point.</returns>
 public static Point4D Multiply(Point4D point, Matrix3D matrix)
 {
     return matrix.Transform(point);
 }
コード例 #17
0
ファイル: Point4D.cs プロジェクト: sjyanxin/WPFSource
 /// <summary>
 /// Compares two Point4D instances for object equality.  In this equality 
 /// Double.NaN is equal to itself, unlike in numeric equality. 
 /// Note that double values can acquire error when operated upon, such that
 /// an exact comparison between two values which 
 /// are logically equal may fail.
 /// </summary>
 /// <returns>
 /// bool - true if the two Point4D instances are exactly equal, false otherwise 
 /// </returns>
 /// <param name='point1'>The first Point4D to compare</param> 
 /// <param name='point2'>The second Point4D to compare</param> 
 public static bool Equals (Point4D point1, Point4D point2)
 { 
     return point1.X.Equals(point2.X) &&
            point1.Y.Equals(point2.Y) &&
            point1.Z.Equals(point2.Z) &&
            point1.W.Equals(point2.W); 
 }
コード例 #18
0
ファイル: Point4D.cs プロジェクト: sjyanxin/WPFSource
        /// <summary>
        /// Parse - returns an instance converted from the provided string using 
        /// the culture "en-US" 
        /// <param name="source"> string with Point4D data </param>
        /// </summary> 
        public static Point4D Parse(string source)
        {
            IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;
 
            TokenizerHelper th = new TokenizerHelper(source, formatProvider);
 
            Point4D value; 

            String firstToken = th.NextTokenRequired(); 

            value = new Point4D(
                Convert.ToDouble(firstToken, formatProvider),
                Convert.ToDouble(th.NextTokenRequired(), formatProvider), 
                Convert.ToDouble(th.NextTokenRequired(), formatProvider),
                Convert.ToDouble(th.NextTokenRequired(), formatProvider)); 
 
            // There should be no more tokens in this string.
            th.LastTokenRequired(); 

            return value;
        }
コード例 #19
0
 /// <summary>
 /// Transforms the given point by the current matrix.
 /// </summary>
 /// <param name="point">Point to transform.</param>
 /// <returns>Transformed point.</returns>
 public Point4D Transform(Point4D point)
 {
     MultiplyPoint(ref point);
     return point;
 }
コード例 #20
0
 /// <summary>
 /// Helper function to transform a Kinect SkeletonPoint using a
 /// transform matrix.
 /// </summary>
 /// <param name="transform">The transform to use</param>
 /// <param name="skeletonPoint">The skeleton point to be transformed</param>
 /// <returns>the transformed skeleton point</returns>
 public static SkeletonPoint TransformSkeletonPoint(Matrix3D transform, SkeletonPoint skeletonPoint)
 {
     var point = new Point4D(skeletonPoint.X, skeletonPoint.Y, skeletonPoint.Z, 1.0);
     point = transform.Transform(point);
     return new SkeletonPoint { X = (float)point.X, Y = (float)point.Y, Z = (float)point.Z };
 }
コード例 #21
0
        public void set_entry_needle(Joints joint)
        {
            double central_angle = get_central_angle();
            Optimizer optimizer = new Optimizer();
            Point4D target = new Point4D(entry_point.X, entry_point.Y, entry_point.Z, central_angle);
            Console.Write("\noTarget entry: {0}, {1}, {2}, {3}", entry_point.X, entry_point.Y, entry_point.Z, central_angle);
            optimizer.point_target = target;
            optimizer.x = new double[] { joint.UpperBevel, joint.LowerBevel, joint.Elbow, joint.twist };
            Joints optimized = optimizer.minimize_angle();
            needle_entry.kinematics.joint.UpperBevel = optimized.UpperBevel;
            needle_entry.kinematics.joint.LowerBevel = optimized.LowerBevel;
            needle_entry.kinematics.joint.Elbow = optimized.Elbow;
            needle_entry.kinematics.joint.twist = optimized.twist;
            needle_entry.update_needle();

            // setup needle_mid
            needle_mid.kinematics.joint.UpperBevel = needle_entry.kinematics.joint.UpperBevel;
            needle_mid.kinematics.joint.LowerBevel = needle_entry.kinematics.joint.LowerBevel;
            needle_mid.kinematics.joint.Elbow = needle_entry.kinematics.joint.Elbow;
            needle_mid.kinematics.joint.twist = needle_entry.kinematics.joint.twist;
            needle_mid.update_needle();
        }
コード例 #22
0
 /// <summary>
 /// Transforms the given points by the current matrix.
 /// </summary>
 /// <param name="points">Points to transform.</param>
 public void Transform(Point4D[] points)
 {
     if (points != null)
     {
         for(int i = 0; i < points.Length; i++)
         {
             MultiplyPoint(ref points[i]);
         }
     }
 }
コード例 #23
0
 // needle center for the needle frame and a point
 public Joints update_trajectory(Joints joint)
 {
     // not used
     double central_angle = get_central_angle();
     Optimizer optimizer = new Optimizer();
     Point4D target = new Point4D(entry_point.X, entry_point.Y, entry_point.Z, central_angle);
     optimizer.point_target = target;
     optimizer.x = new double[] { joint.UpperBevel, joint.LowerBevel, joint.Elbow, joint.twist };
     Joints optimized = optimizer.minimize_angle();
     return optimized;
     //Vector3D projected_exit_point = project_point(exit_point, needle_normal, needle_point);
     //Matrix3D head = calculate_needle_tip(entry_point, projected_exit_point, needle_normal);
 }
 public Point4D Transform(Point4D point)
 {
     return(default(Point4D));
 }
コード例 #25
0
ファイル: Point4D.cs プロジェクト: JianwenSun/cc
 /// <summary>
 /// Addition.
 /// </summary>
 /// <param name="point1">First point being added.</param>
 /// <param name="point2">Second point being added.</param>
 /// <returns>Result of addition.</returns>
 public static Point4D Add(Point4D point1, Point4D point2)
 {
     return new Point4D(point1._x + point2._x, 
                        point1._y + point2._y, 
                        point1._z + point2._z,
                        point1._w + point2._w);
 }
コード例 #26
0
        //  Multiplies the given Point4D by this matrix.
        //
        //  The point is modified in place for performance.
        //
        internal void MultiplyPoint(ref Point4D point)
        {
            if (IsDistinguishedIdentity)
                return;

            double x = point.X;
            double y = point.Y;
            double z = point.Z;
            double w = point.W;

            point.X = x*_m11 + y*_m21 + z*_m31 + w*_offsetX;
            point.Y = x*_m12 + y*_m22 + z*_m32 + w*_offsetY;
            point.Z = x*_m13 + y*_m23 + z*_m33 + w*_offsetZ;
            point.W = x*_m14 + y*_m24 + z*_m34 + w*_m44;
        }
コード例 #27
0
        internal override RayHitTestParameters RayFromViewportPoint(Point p, Size viewSize, Rect3D boundingRect, out double distanceAdjustment)
        {
            //
            //  Compute rayParameters
            //

            // Find the point on the projection plane in post-projective space where
            // the viewport maps to a 2x2 square from (-1,1)-(1,-1).
            Point np = M3DUtil.GetNormalizedPoint(p, viewSize);

            // This ray is consistent with a left-handed camera
            // MatrixCamera should be right-handed and should be updated to be so.

            // So (conceptually) the user clicked on the point (np.X,
            // np.Y, 0) in post-projection clipping space and the ray
            // extends in the direction (0, 0, 1) because our ray
            // after projection looks down the positive z axis.  We
            // need to convert this ray and direction back to world
            // space.

            Matrix3D worldToCamera = GetViewMatrix() * ProjectionMatrix;
            Matrix3D cameraToWorld = worldToCamera;

            if (!cameraToWorld.HasInverse)
            {
                // When the following issue is addressed we should
                //   investigate if the custom code paths in Orthographic and PerspectiveCamera
                //   are worth keeping.  They may not be buying us anything aside from handling
                //   singular matrices.

                // Need to handle singular matrix cameras
                throw new NotSupportedException(SR.Get(SRID.HitTest_Singular));
            }

            cameraToWorld.Invert();

            Point4D origin4D = new Point4D(np.X, np.Y, 0, 1) * cameraToWorld;
            Point3D origin   = new Point3D(origin4D.X / origin4D.W,
                                           origin4D.Y / origin4D.W,
                                           origin4D.Z / origin4D.W);

            // To transform the direction we use the Jacobian of
            // cameraToWorld at the point np.X,np.Y,0 that we just
            // transformed.
            //
            // The Jacobian of the homogeneous matrix M is a 3x3 matrix.
            //
            // Let x be the point we are computing the Jacobian at, and y be the
            // result of transforming x by M, i.e.
            // (wy w) = (x 1) M
            // Where (wy w) is the homogeneous point representing y with w as its homogeneous coordinate
            // And (x 1) is the homogeneous point representing x with 1 as its homogeneous coordinate
            //
            // Then the i,j component of the Jacobian (at x) is
            // (M_ij - M_i4 y_j) / w
            //
            // Since we're only concerned with the direction of the
            // transformed vector and not its magnitude, we can scale
            // this matrix by a POSITIVE factor.  The computation
            // below computes the Jacobian scaled by 1/w and then
            // after we normalize the final vector we flip it around
            // if w is negative.
            //
            // To transform a vector we just right multiply it by this Jacobian matrix.
            //
            // Compute the Jacobian at np.X,np.Y,0 ignoring the constant factor of w.
            // Here's the pattern
            //
            // double Jij = cameraToWorld.Mij - cameraToWorld.Mi4 * origin.j
            //
            // but we only need J31,J32,&J33 because we're only
            // transforming the vector 0,0,1

            double J31 = cameraToWorld.M31 - cameraToWorld.M34 * origin.X;
            double J32 = cameraToWorld.M32 - cameraToWorld.M34 * origin.Y;
            double J33 = cameraToWorld.M33 - cameraToWorld.M34 * origin.Z;

            // Then multiply that matrix by (0, 0, 1) which is
            // the direction of the ray in post-projection space.
            Vector3D direction = new Vector3D(J31, J32, J33);

            direction.Normalize();

            // We multiplied by the Jacobian times W, so we need to
            // account for whether that flipped our result or not.
            if (origin4D.W < 0)
            {
                direction = -direction;
            }

            RayHitTestParameters rayParameters = new RayHitTestParameters(origin, direction);

            //
            //  Compute HitTestProjectionMatrix
            //

            // The viewportMatrix will take normalized clip space into
            // viewport coordinates, with an additional 2D translation
            // to put the ray at the origin.
            Matrix3D viewportMatrix = new Matrix3D();

            viewportMatrix.TranslatePrepend(new Vector3D(-p.X, viewSize.Height - p.Y, 0));
            viewportMatrix.ScalePrepend(new Vector3D(viewSize.Width / 2, -viewSize.Height / 2, 1));
            viewportMatrix.TranslatePrepend(new Vector3D(1, 1, 0));

            // `First world-to-camera, then camera's projection, then normalized clip space to viewport.
            rayParameters.HitTestProjectionMatrix =
                worldToCamera *
                viewportMatrix;

            //
            // MatrixCamera does not allow for Near/Far plane adjustment, so
            // the distanceAdjustment remains 0.
            //
            distanceAdjustment = 0.0;

            return(rayParameters);
        }
コード例 #28
0
ファイル: Viewport3DVisual.cs プロジェクト: mind0n/hive
        internal Point WorldToViewport(Point4D point)
        {
            double aspectRatio = M3DUtil.GetAspectRatio(Viewport.Size);
            Camera camera = Camera;

            if (camera != null)
            {
                Matrix3D viewProjMatrix = camera.GetViewMatrix() * camera.GetProjectionMatrix(aspectRatio);
                point *= viewProjMatrix;

                Point point2D = new Point(point.X/point.W, point.Y/point.W);
                point2D *= M3DUtil.GetHomogeneousToViewportTransform(Viewport);

                return point2D;
            }
            else
            {
                return new Point(0,0);
            }
        }
コード例 #29
0
ファイル: Transform3D.cs プロジェクト: JianwenSun/cc
 /// <summary>
 ///     Transforms the given list of points.
 /// </summary>
 /// <param name="points">List of points.</param>
 public void Transform(Point4D[] points)
 {
     Value.Transform(points);
 }
 public void Transform(Point4D[] points)
 {
 }
コード例 #31
0
ファイル: Transform3D.cs プロジェクト: JianwenSun/cc
 /// <summary>
 ///     Transforms the given point.
 /// </summary>
 /// <param name="point">Point to transform.</param>
 /// <returns>Transformed point.</returns>
 public Point4D Transform(Point4D point)
 {
     return Value.Transform(point);
 }
コード例 #32
0
ファイル: Point4D.cs プロジェクト: sjyanxin/WPFSource
 /// <summary>
 /// Equals - compares this Point4D with the passed in object.  In this equality
 /// Double.NaN is equal to itself, unlike in numeric equality. 
 /// Note that double values can acquire error when operated upon, such that
 /// an exact comparison between two values which 
 /// are logically equal may fail. 
 /// </summary>
 /// <returns> 
 /// bool - true if "value" is equal to "this".
 /// </returns>
 /// <param name='value'>The Point4D to compare to "this"</param>
 public bool Equals(Point4D value) 
 {
     return Point4D.Equals(this, value); 
 } 
コード例 #33
0
ファイル: PointGeometryBuilder.cs プロジェクト: ondrej11/o106
        /// <summary>
        /// Creates the positions for the specified points.
        /// </summary>
        /// <param name="points">
        /// The points.
        /// </param>
        /// <param name="size">
        /// The size of the points.
        /// </param>
        /// <param name="depthOffset">
        /// The depth offset. A positive number (e.g. 0.0001) moves the point towards the camera.
        /// </param>
        /// <returns>
        /// The positions collection.
        /// </returns>
        public Point3DCollection CreatePositions(IList<Point3D> points, double size = 1.0, double depthOffset = 0.0)
        {
            double halfSize = size / 2.0;
            int numPoints = points.Count;

            var outline = new[]
                {
                    new Vector(-halfSize, halfSize), new Vector(-halfSize, -halfSize), new Vector(halfSize, halfSize),
                    new Vector(halfSize, -halfSize)
                };

            var positions = new Point3DCollection(numPoints * 4);

            for (int i = 0; i < numPoints; i++)
            {
                var screenPoint = (Point4D)points[i] * this.visualToScreen;

                double spx = screenPoint.X;
                double spy = screenPoint.Y;
                double spz = screenPoint.Z;
                double spw = screenPoint.W;

                if (!depthOffset.Equals(0))
                {
                    spz -= depthOffset * spw;
                }

                var p0 = new Point4D(spx, spy, spz, spw) * this.screenToVisual;
                double pwinverse = 1 / p0.W;

                foreach (var v in outline)
                {
                    var p = new Point4D(spx + v.X * spw, spy + v.Y * spw, spz, spw) * this.screenToVisual;
                    positions.Add(new Point3D(p.X * pwinverse, p.Y * pwinverse, p.Z * pwinverse));
                }
            }

            positions.Freeze();
            return positions;
        }
コード例 #34
0
 /// <summary>
 /// Transforms the given point by the current matrix.
 /// </summary>
 /// <param name="point">Point to transform.</param>
 /// <returns>Transformed point.</returns>
 public Point4D Transform(Point4D point)
 {
     MultiplyPoint(ref point);
     return(point);
 }
コード例 #35
0
 /// <summary>
 /// Point4D * Matrix3D multiplication.
 /// </summary>
 /// <param name="point">Point being transformed.</param>
 /// <param name="matrix">Transformation matrix applied to the point.</param>
 /// <returns>Result of the transformation matrix applied to the point.</returns>
 public static Point4D Multiply(Point4D point, Matrix3D matrix)
 {
     return(matrix.Transform(point));
 }
コード例 #36
0
        /// <summary>
        /// Gets the billboard positions with the current screen transform.
        /// </summary>
        /// <param name="billboards">The billboards.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="pinWidth">Width of the pins.</param>
        /// <returns>The mesh vertices.</returns>
        public Point3DCollection GetPinPositions(IList<Billboard> billboards, Vector offset, double pinWidth)
        {
            var pinStart = new Point(0, 0);
            var pinEnd = pinStart + (offset * (1 + (2 * pinWidth / offset.Length)));
            var pinNormal = new Vector(pinEnd.Y, -pinEnd.X);
            pinNormal.Normalize();
            pinNormal *= pinWidth * 0.5;

            var pinPoints = new Point[4];
            pinPoints[0] = new Point(0, 0) + (pinNormal * 0.5);
            pinPoints[1] = new Point(0, 0) - (pinNormal * 0.5);
            pinPoints[2] = pinEnd - pinNormal;
            pinPoints[3] = pinEnd + pinNormal;

            var positions = new Point3DCollection(billboards.Count * 4);
            foreach (var bb in billboards)
            {
                Point4D screenPoint;
                if (!bb.WorldDepthOffset.Equals(0))
                {
                    var viewPoint = (Point4D)bb.Position * this.visualToProjection;
                    screenPoint = new Point4D(viewPoint.X, viewPoint.Y, viewPoint.Z + bb.WorldDepthOffset, viewPoint.W) * this.projectionToScreen;
                }
                else
                {
                    screenPoint = (Point4D)bb.Position * this.visualToScreen;
                }

                double spw = screenPoint.W;
                double spx = screenPoint.X;
                double spy = screenPoint.Y;
                double spz = screenPoint.Z - ((bb.DepthOffset - 1e-5) * spw);

                foreach (var pinPoint in pinPoints)
                {
                    var p = new Point4D(spx + (pinPoint.X * spw), spy + (pinPoint.Y * spw), spz, spw) * this.screenToVisual;
                    double wi = 1 / p.W;
                    positions.Add(new Point3D(p.X * wi, p.Y * wi, p.Z * wi));
                }
            }

            positions.Freeze();
            return positions;
        }
コード例 #37
0
ファイル: Point4D.cs プロジェクト: JianwenSun/cc
 /// <summary>
 /// Subtraction.
 /// </summary>
 /// <param name="point1">Point from which we are subtracting the second point.</param>
 /// <param name="point2">Point being subtracted.</param>
 /// <returns>Vector between the two points.</returns>
 public static Point4D Subtract(Point4D point1, Point4D point2)
 {
     return new Point4D(point1._x - point2._x, 
                        point1._y - point2._y, 
                        point1._z - point2._z,
                        point1._w - point2._w);
 }
コード例 #38
0
        // This method performs the Point operations
        public 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":
                    {
                        // Converts a String to a Point using a PointConverter
                        // Returns a Point.

                        PointConverter pConverter = new PointConverter();
                        Point pointResult = new Point();
                        string string1 = "10,20";

                        pointResult = (Point)pConverter.ConvertFromString(string1);
                        // pointResult is equal to (10, 20)

                        // Displaying Results
                        syntaxString = "pointResult = (Point)pConverter1.ConvertFromString(string1);";
                        resultType = "Point";
                        operationString = "Converting a String to a Point";
                        ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb2":
                    {
                        // Converts a String to a Vector using a VectorConverter
                        // Returns a Vector.

                        VectorConverter vConverter = new VectorConverter();
                        Vector vectorResult = new Vector();
                        string string1 = "10,20";

                        vectorResult = (Vector)vConverter.ConvertFromString(string1);
                        // vectorResult is equal to (10, 20)

                        // Displaying Results
                        syntaxString = "vectorResult = (Vector)vConverter.ConvertFromString(string1);";
                        resultType = "Vector";
                        operationString = "Converting a String into a Vector";
                        ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb3":
                    {
                        // Converts a String to a Matrix using a MatrixConverter
                        // Returns a Matrix.

                        MatrixConverter mConverter = new MatrixConverter();
                        Matrix matrixResult = new Matrix();
                        string string2 = "10,20,30,40,50,60";

                        matrixResult = (Matrix)mConverter.ConvertFromString(string2);
                        // matrixResult is equal to (10, 20, 30, 40, 50, 60)

                        // Displaying Results
                        syntaxString = "matrixResult = (Vector)mConverter.ConvertFromString(string2);";
                        resultType = "Matrix";
                        operationString = "Converting a String into a Matrix";
                        ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb4":
                    {
                        // Converts a String to a Point3D using a Point3DConverter
                        // Returns a Point3D.

                        Point3DConverter p3DConverter = new Point3DConverter();
                        Point3D point3DResult = new Point3D();
                        string string3 = "10,20,30";

                        point3DResult = (Point3D)p3DConverter.ConvertFromString(string3);
                        // point3DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "point3DResult = (Point3D)p3DConverter.ConvertFromString(string3);";
                        resultType = "Point3D";
                        operationString = "Converting a String into a Point3D";
                        ShowResults(point3DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb5":
                    {
                        // Converts a String to a Vector3D using a Vector3DConverter
                        // Returns a Vector3D.

                        Vector3DConverter v3DConverter = new Vector3DConverter();
                        Vector3D vector3DResult = new Vector3D();
                        string string3 = "10,20,30";

                        vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3);
                        // vector3DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3);";
                        resultType = "Vector3D";
                        operationString = "Converting a String into a Vector3D";
                        ShowResults(vector3DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb6":
                    {
                        // Converts a String to a Size3D using a Size3DConverter
                        // Returns a Size3D.

                        Size3DConverter s3DConverter = new Size3DConverter();
                        Size3D size3DResult = new Size3D();
                        string string3 = "10,20,30";

                        size3DResult = (Size3D)s3DConverter.ConvertFromString(string3);
                        // size3DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "size3DResult = (Size3D)v3DConverter.ConvertFromString(string3);";
                        resultType = "Size3D";
                        operationString = "Converting a String into a Size3D";
                        ShowResults(size3DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                case "rb7":
                    {
                        // Converts a String to a Point4D using a Point4DConverter
                        // Returns a Point4D.

                        Point4DConverter p4DConverter = new Point4DConverter();
                        Point4D point4DResult = new Point4D();
                        string string4 = "10,20,30,40";

                        point4DResult = (Point4D)p4DConverter.ConvertFromString(string4);
                        // point4DResult is equal to (10, 20, 30)

                        // Displaying Results
                        syntaxString = "point4DResult = (Point4D)v3DConverter.ConvertFromString(string3);";
                        resultType = "Point4D";
                        operationString = "Converting a String into a Point4D";
                        ShowResults(point4DResult.ToString(), syntaxString, resultType, operationString);
                        break;
                    }

                    default:
                    break;

            } //end switch
        }
コード例 #39
0
 /// <summary>
 ///     Transforms the given point.
 /// </summary>
 /// <param name="point">Point to transform.</param>
 /// <returns>Transformed point.</returns>
 public Point4D Transform(Point4D point)
 {
     return(Value.Transform(point));
 }