c++vectorglm-mathcross-product# Cross product of a vector with local y direction and another vector

So I have a cube represented by a `glm::mat4 m_yellow_mat`

and I performed a `30 degree`

rotation around `z-axis`

```
m_yellow_mat = glm::rotate(m_yellow_mat, glm::radians(30), glm::vec3(0, 0, 1));
```

Now refer the below picture

I want to find the cross product between the blue vector and red vector

I know the blue vector, but not sure how to find the red vector? Red vector represents the direction of the local y axis of cube?

```
cross( ?????? , blue_vector);
```

Solution

The local y axis in world space is stored in the second row of the matrix:

```
vec3 yaxis_world = normalize(m_yellow_mat[1][0], m_yellow_mat[1][1], m_yellow_mat[1][2]);
```

Explanation:

The y axis in object space (let's call it yaxis) is by definition [0,1,0]. In order to transform a vector from object space to world space, we multiply the vector with the model matrix. Since we are interested in a direction, the homogeneous coordinate has to be 0:

```
axisy_world = modelMatrix * yaxis
axisy_world = modelMatrix * [0,1,0,0]
```

When looking at the matrix multiplication, we notice that the this will return exactly the second row of the matrix.

Note, that the result has to be normalized in order to cancel out scaling factors from the matrix. If it is guaranteed that only translations/rotations are contained, the normalization can be skipped.

- How to read two lines with a random numbers count from input into two arrays
- RobotC - Programming an Elevator
- Strange behavior when adding longs in RobotC
- Do unsigned functions have to return something?
- Duplicate symbols in Microsoft C library
- Using ssize_t vs int
- undefined reference to `sctp_get_no_strms'
- Passing pointer of an array to a function in C
- C Program to find day of week given date
- Embedding Python in C, linking fails with undefined reference to `Py_Initialize'
- Converting python string object to c char* using ctypes
- State-of-the-art for embedding scriptable, interactive SVG in Gtk+ applications?
- Does the stack get freed after scope block?
- VS Code's C/C++ extension says the C23 true and false keywords are undefined
- How to declare a pointer to a character array in C?
- How to get one character at a time
- How to get a timeout to work when connecting to a socket
- Periodically trigger pthread workers and wait for completion
- The return value goes wrong if I release something else
- Have two C compilers
- My function is not reading data from the input file properly (C)
- Consolidating GNU C's and C23's deprecated function attribute
- Infix to postfix left one parentheses at the end when expression is fully enclosed
- Casting a function pointer to another type
- Runtime cast of void pointer
- customize printf with extra common parameters
- error: unknown type name ‘bool’
- Passing list as a parameter to a function in c
- function to fill data into buffer with append everytime
- reverse array in range in C