How to implement the rotation of a two-dimensional vector by 45 degrees, found solutions for 90, 180, 270. Such a sweep can be realized only through the rotation matrix?

Another question regarding the future use of vector elements

int E; cout << " Input E "; cin >> E; for (int y = 0; y < col; ++y) { if ((array[y][y] == (min - E)) || (array[y][y] == (min + E))) { cout << "Element #" << y+1 << ":match "; } else { cout << "Element #" << y + 1 << ":not match "; } } 

In this case, the values ​​are simply checked for coincidences with the condition (which is logical), but how to realize that the values ​​that are suitable were used for further calculations?

    2 answers 2

    To rotate the two-dimensional vector (x, y) by an angle a , you need to do the following calculations (note that a is measured in radians, not degrees) here:

     cs = cos(a); sn = sin(a); rx = x * cs - y * sn; ry = x * sn + y * cs; 

    Accordingly, in the case of a 45 degree rotation, the sine and cosine are equal to sqrt(2)/2 , therefore the resulting vector (rx, ry) can be found as follows:

     cs = sn = sqrt(2)/2; rx = x * cs - y * sn; ry = x * sn + y * cs; 

    The second question about your use in further calculations is extremely difficult to answer, because it is not clear what it is. Perhaps you want values ​​that are suitable for the conditions, add to some list, then to process them. Explain exactly what is needed here.

    • For the first answer, thank you) Very much helped. Tangent second, in the future, I want to use the values ​​to calculate the Euclidean distance. I found the values, but I don’t understand how to use them immediately in the equation - Castly6
    • It did not become clearer. I continue to suspect that you need to add the appropriate values ​​to a separate list, and then perform the necessary calculations on them. - Ilya
    • Oh, how to more accurately formulate the question. I sifted out the values ​​in my two-dimensional vector according to the condition. Now I want the values ​​that come up, I could use in solving the equation. For example - if in my matrix there are numbers suitable for the conditions (for example, E1 = max + x and E2 = min + x) then I could use them separately from the matrix and the equation. I hope it became clearer. By the way, how to add them to a separate list? - Castly6
    • To add the item y+1 to the lst list, run lst.append(y+1) . - Ilya
    • one
      I note that here multiplied by the rotation matrix is ​​deployed. This is the easiest way :) - D-side

    To weed out the extra elements there are 2 ways:

    1. Filtering an existing dataset. To do this, the standard library has a function remove_if
    2. Create a new set based on this. Copy_if is used for this .
    • Completely confused with the implementation, how to create a new set? I do not know the exact values ​​that need to be added to this set. The matrix is ​​filled randomly. How in this case to implement the creation of a narab so that values ​​are added that meet the requirements? - Castly6
    • 2
      @ Castly6 You are processing not a matrix, but its diagonal, which can be represented in a linear form. For example, copying all the elements into std::vector . - fshp