1 / 18

3D Vector & Matrix

3D Vector & Matrix. Chapter 2. Vector. Definition: Vector is a line segment that has the direction. The length of the line segment is called the magnitude or size of the vector. . If two vectors have the same magnitude and direction, then they are considered as the same vectors.

argyle
Download Presentation

3D Vector & Matrix

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 3D Vector & Matrix Chapter 2

  2. Vector Definition: Vector is a line segment that has the direction. The length of the line segment is called the magnitude or size of the vector. If two vectors have the same magnitude and direction, then they are considered as the same vectors

  3. Vector3(float, float, float) 3D DirectX has class If we set the beginning point of a vector at origin, then the ending point of the vector is uniquely defined. Therefore we can use vector to define a point, like vertex. public Vector3 ( float valueX, float valueY, float valueZ )

  4. Addition of Vector3 We can directly use + to add two vectors.

  5. Subtraction of Vector3 We can directly use - to subtract two vectors.

  6. Dot Product of Vector3 staticfloat Dot ( Vector3 left, Vector3 right ) If Vector3 v1 = new Vector3(a1, b1, c1); And Vector3 v2 = new Vector3(a2, b2, c2); Then v1o v2 = a1×a2 + b1×b2 + c1×c2

  7. Cross Product of Vector3 staticVector3 Cross( Vector3 left, Vector3 right ) q

  8. Other methods of Vector3 float Length( ) Return the length of the vector Vector3 Normalize( ) Return the vector that has the same direction and length=1 Vector3 Multiply(floata ) We can directly use * to multiply a vector by a float number

  9. 3D Matrix struct Matrix{ float M11, M12, M13, M14; float M21, M22, M23, M24; float M31, M32, M33, M34; float M41, M42, M43, M44; }; An array of floats that represent a 4x4 matrix, where i is the row number and jis the column number. For example, M34 means the component in the third row and fourth column

  10. Matrix Properties float Determinant { get; } Call Matrix.Identity to get an identity matrix. static Matrix Identity { get; } static Matrix Zero{ get; } Call Matrix.Zero to get an empty matrix.

  11. Matrix Rotation Methods static Matrix RotationX (floatq) Call Matrix.RotationX to get a matrix that represents the rotation about x-axis by angle q static Matrix RotationY (floatq) static Matrix RotationZ (floatq) static Matrix RotationAxis(Vector3 axis, floatq) Get a rotation matrix about any axis

  12. Actually,

  13. Matrix Translation Methods static Matrix Translation(float a,float b,float c) This is the operation (x, y, z)  (x+a, y+b, z+c) The matrix is static Matrix Translation(Vector3 v) Because that

  14. Matrix Transpose Method static Matrix Transpose(Matrix m) If we have matrix Then its transpose matrix is

  15. Matrix Inverse Method Matrix Invert() static Matrix Invert(Matrix m ) Let If A*B = I (identity matrix) , then B is call the inverse matrix of A. Also A is the inverse matrix of B.

  16. Matrix operator Method Matrix has +, -, * operators static Matrix operator + ( Matrix m1, Matrix m2) static Matrix operator - ( Matrix m1, Matrix m2) static Matrix operator * ( Matrix m1, Matrix m2) Which means they can directly do operations Matrix m1, m2; Matrix m_sum = m1 + m2; Matrix m_minus = m1 - m2; Matrix m_product = m1* m2;

  17. World Coordinate Every Matrix object is a transformation of the 3D space. The following is the code to set this transformation. Matrix m1, m2; m_device.Transform.World = Matrix.Identity(); Draw Figure 1; // under transformation m1 m_device.Transform.World = m1; Draw Figure 2; // under transformation m1 Draw Figure 3; // under transformation m1 m_device.Transform.World = m2; Draw Figure 4; // under transformation m2 only In the above, the world coordinate of Figure 1 could also under transformation by Matrix m1;

  18. Matrix combination We have two transformations whose matrices are m1 and m2. If applying those two transformations consecutively to our 3D world, we need to do Matrix multiplication. In 3D program the left matrix takes action first. (In Mathematics, the right one takes action first.) Matrix matRotation, matTranslation; m_device.Transform.World = matTranslation* matRotation ; Draw Figure; // first translation then rotation

More Related