Forward (vector) Cross multiplication programming implementation

Source: Internet
Author: User

At the invitation of a friend, I specially used C language to implement the cross multiplication of 3D vectors, because he could not find the code about vector multiplication on the Internet. Now that I have written this article, I would like to share it with you. There are not many considerations for the data structure during the writing, but I will focus on the implementation of the computation process. If you have good suggestions, I would like to leave a message.
 
//// // Main. c /////////////////////////////////////// //
# Include <stdio. h>
# Include "vector_multiply.h"
Int main (void)
{
Float a [3] = {1.0, 2.0, 3.0}, B [3] = {7.0, 8.0, 9.0}, c [3] = {0 };
 
Vector_multiply (a, B, c );
Printf ("%. 1f: %. 1f: %. 1f \ n", c [0], c [1], c [2]);
 
Return (0 );
}
 
/// // Vector_multiply.c //// ///////////////////////////
Void vector_multiply (float a [], float B [], float c []) {
Int I, j, k, n = 0;
/* According the formula we can get these marks */
Int d [3] [4] = {0, 1,-1, 0}, {0,-1, 1, 0}, {0, 1,-1, 0 }};
 
For (k = 0; k <3; k ++ ){
For (I = 0; I <3; I ++ ){
For (j = 0; j <3; j ++)
If (k! = I & k! = J)
C [k] + = a [I] * B [j] * d [k] [n ++];
}
N = 0;
}
Return;
}
 
//// // Vector_multiply.h /////// ///////////////////////////
# Ifndef VECTOR_MULTIPLY_H _
# Define VECTOR_MULTIPLY_H _
Void vector_multiply (float a [], float B [], float c []);
# Endif/* VECTOR_MULTIPLY_H _*/
//////////////////////////////////////// //////////////////////////////////////// ///
Gcc main. c vector_multiply.c-o VectorOperations
 
 
Finally, the formula of the vector cross multiplication is left:
Vector: u = (u1, u2, u3) v = (v1, v2, v3)
Cross Product formula: u x v = | I j k |
| A1 b1 c1 |
| A2 b2 c2 |
= {U2v3-v2u3, u3v1-v3u1, u1v2-u2v1}

Related Article

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.