A vector orthogonal projection to B

Source: Internet
Author: User
Tags scalar

1. Even a vector dot multiply

Two vector points by
static double Dot (const double A[3],const Double b[3]) {return
    (A[0]*b[0] + a[1]*b[1] + a[2]*b[2);
}

2. Two vector x multiplication

Vector x by
void Crossvector (const double A[3],const double b[3],double normal[3]) {
    normal[0] = a[1] * b[2]-a[2] * b[ 1];
    NORMAL[1] = a[2] * b[0]-a[0] * b[2];
    NORMAL[2] = a[0] * b[1]-a[1] * b[0];

3. Multiply a value by a vector

Product
static void Multiplyvector (double a[3],double scalar) for a vector {for
    (unsigned int i=0; i<3; i++) {
        a[ I] *= scalar;
    }

4.a vector orthogonal projection to B

A vector orthogonal projection to B
-bool Vectorprojection (const double A[3],const double b[3],double a1[3]) {
    double bsq = Dot (b,b);
    Determine whether B is 0
    if (0 = bsq) {
        a1[0] = 0;
        A1[1] = 0;
        A1[2] = 0;
        return false;
    }

    float ratio = Dot (a,b)/bsq;
    for (unsigned int i=0; i<3; i++) {
        a1[i] = B[i];
    }
    Multiplyvector (a1,ratio);
    return true;
}

A detailed interpretation of https://www.cnblogs.com/graphics/archive/2010/08/03/1791626.html by vector projection

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.