Vector

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How can I create a user defined data type that could be used to represent a three dimensional vector.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
typedef struct
{
    float x;
    float y;
    float z;
} vector;

...

vector myVector;

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Koshchi wrote:

typedef struct
{
    float x;
    float y;
    float z;
} vector;

...

vector myVector;

Thanks for the quick response, but it needs to be a user defined data type and not a structure. So would the following be okay...

typedef float Vector[3];

then say to declare an array of four vectors I could simple say...

Vector image_vector[4];

Maybe I'll stick to the structure... :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Thanks for the quick response, but it needs to be a user defined data type and not a structure.

But that is a user defined data type (that also happens to be a struct). If you want an array instead, your method will work just fine.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, I think I was barking up the wrongs tree, your way is perfect for what I want....