cancel
Showing results for 
Search instead for 
Did you mean: 

3D vectors in C++

DetlefS
Associate III

Hi,

recently I detected "complex.h" and the float complex data type for C++ project files. Since then dealing with complex numbers got very easy.

 

I would appreciate the same ease of use for 3D float vectors, i.e. I need a float vector data type and the vector operators.

Is there a comparable include for 3D vectors?

THX

Cheers

Detlef

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Fixed length arrays are implemented in <array> in C++.

#include <array>

std::array<float, 3> vector;

 

std::array - cppreference.com

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

5 REPLIES 5
Andrew Neil
Evangelist III

I would think this would be generic C++ - not specific to STM32 or CubeIDE ?

What does your favourite internet search engine say?

Have you tried  a search on GitHub ?

 

eg, https://github.com/cdelv/Vector3D 

Hi,

the very first lines of the code in github 

#include <iostream>
#include <cmath>
using namespace std; 

show errors on CubeIDE.

I'm good in C but a C++ newbie. Fixed length vectors are not integrated in C++, as far as I know. Reportedly there are some 3D vector implementations out in the wild. I have the hope this is already included in the compiler for CubeIDE !?

Cheers

Detlef

 

TDK
Guru

Fixed length arrays are implemented in <array> in C++.

#include <array>

std::array<float, 3> vector;

 

std::array - cppreference.com

If you feel a post has answered your question, please click "Accept as Solution".
DetlefS
Associate III

Yes,

it works.

 

The pitfall: 'target language C++' is chosen, but you have to rename main.c to main.cpp manually. For main.c gcc throws an error, g++ for main.cpp ist working fine.

 

THX

Cheers

Detlef


@DetlefS wrote:

The pitfall: 'target language C++' is chosen, but you have to rename main.c to main.cpp manually.


Now that is a bit dumb. 🙄

 


@DetlefS wrote:

For main.c gcc throws an error,lef


Yes: GCC will, by default, compile a file with .c extension as C - not as C++