what does a 3D vector look like?

if 2D vectors is rows and columns how bout 3D vectors?

example like dot product and cross product
how is the variables from a dot product or cross product stored in a vector

@seungyeon

You are getting confused between a 2-dimensional ARRAY (often called a matrix, and having 2 INDICES, e.g. Mij) and a 1-dimensional VECTOR (which has 1 INDEX, e.g. Vi).

When we talk about 3-d SPACE we are referring to the number of components of that vector, not indices.

A dot product is a scalar; it won't be stored in a vector.
A cross product is another 3-component vector.

Sadly, the c++ definition of "vector" doesn't correspond exactly to the mathematical one.
what does a 3D vector look like?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <vector>

int main()
{
    std::vector<std::vector<int>> my2Dvec(4, std::vector<int>(3,0));
    std::vector<std::vector<std::vector<int>>> my3Dvec(5, std::vector<std::vector<int>>(4, std::vector<int>(3,0)));

    std::cout << "my2Dvec \n";
    for (const auto& elemOuter : my2Dvec)
    {
        for (const auto& elemInner : elemOuter)
        {
            std::cout << elemInner << " ";
        }
        std::cout << "\n";
    }
    std::cout << "\nmy3Dvec \n";
    for (const auto & elemOuter : my3Dvec)
    {
        for (const auto& elemMid : elemOuter)
        {
            for (const auto& elemInner : elemMid)
            {
                std::cout << elemInner << " ";
            }
            std::cout << "\n";
        }
        std::cout << "\n";
    }
}
closed account (48T7M4Gy)
http://en.cppreference.com/w/cpp/algorithm/inner_product
Topic archived. No new replies allowed.