) Managed DirectX + C # Development (Getting Started) (3)

Source: Internet
Author: User

Chapter 2 vector operations (2)

7: maximum and minimum values of VectorsThe maximum value is obtained from the two vectors x, y, and z respectively to form a new vector. The minimum value is obtained from the two vectors x, y, and z respectively to form a new vector; run the following code: Private void vectormax () {vector3 vec1 = new vector3 (6, 2, 3); vector3 vec2 = new vector3 (, 5); vector3 vector3.maximize (vec1, vec2); string disstring = "V (6, 2, 3) and V (1, 2, 5) maximum value:/N"; disstring + = "V (" + vec3.x. tostring () + "," + vec3.y. tostring () + "," + vec3.z. tostring () + ")/n"; MessageBox. show (disstring, "Maximum vector");} The execution result is: 8: Find an interpolation vector between two vectorsThe formula for calculating the vector value is pleft + interpolater (pright-pleft ). example code: Private void vectorlerp () {vector3 vec1 = new vector3 (6, 2, 3); vector3 vec2 = new vector3 (1, 2, 5); vector3 vector3 = vector3.lerp (vec1, vec2, 0.5f); string disstring = "an interpolation vector between V (6, 2, 3) and V (1, 2, 5):/N "; disstring + = "V (" + vec3.x. tostring () + "," + vec3.y. tostring () + "," + vec3.z. tostring () + ")/n"; MessageBox. show (disstring, "interpolation vector");} execution result: Apparently 3.5 = 6 + (1-6) * 0.5; 2 = 2 + (2-2) * 0.5; 4 = 3 + (5-3) * 0.5; 9: Point productIn mathematics, Point product is the product of two vectors. Calculate according to the equation below: An important theorem of dot product is called the cosine law? V = | u | v | cos θ, indicating that the dot product of two vectors is the product of their modulus and cosine of the angle. Therefore, if both U and V are units vectors, then u? V is the cosine of their angle. Some useful features of dot product (1) U? V = 0, then u then v. (2) U? V> 0, then the angle θ of the two vectors is less than 90 degrees. (3) U? V <0, then the angle θ of the two vectors is greater than 90 degrees. For example, the following example shows the dot product of two vectors: Private void vectordot () {vector3 vec1 = new vector3 (6, 2, 3); vector3 vec2 = new vector3 (, 5 ); float dotvalue = vector3.dot (vec1, vec2); Point product of string disstring = "V (6, 2, 3) and V (1, 2, 5):/N" + dotvalue. tostring (); MessageBox. show (disstring, "vector dot product");} The execution result is as follows: 10: Cross ProductBy multiplying the two vectors u and v to the other vector p, the u and v vectors are multiplied by the cross to obtain the vector p, and the vector p is perpendicular to the u and v. That is to say, vector p is perpendicular to u and v. The formula is: that is, obtain the following vectors x, y, and z values: Note: vector p is perpendicular to the plane determined by u and v, the direction varies with the coordinate system of the left and right hands. The following code uses the cross product of two vectors in the xoy plane. The returned value is perpendicular to the xoy plane, that is, parallel to the Z axis. Private void vectorcross () {vector3 vec1 = new vector3 (6, 4, 0); vector3 vec2 = new vector3 (-1, 2, 0); vector3 vec3 = vector3.cross (vec1, vec2 ); string disstring = "V (, 0) and V (-, 0) Cross Product:/N"; disstring + = "V (" + vec3.x. tostring () + "," + vec3.y. tostring () + "," + vec3.z. tostring () + ")/n"; MessageBox. show (disstring, "vector cross product");} The execution result is: transferred from: dandancool http://blog.csdn.net/dandancool/archive/2007/06/26/1666609.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.