I have never programmed in C and have not programmed in C++ for a little while and either way, I am still learning.
I am writing a program in C and am converting a MATLAB program to this C program. I have a lot of variables from MATLAB that are cartesian coordinates, X Y Z, of points. Is there a variable type I could use built into C? I need to subtract different points and also do other operations on them. Any suggestions?
Thanks,
DemiSheep
Edit:
Ok I have another question. I want to make sure this is a good idea. (But first, with stackoverflow is this how I should post more information to my post, by editing my original post? -Thanks!)
Question:
I have an object with several characteristics. Say it’s a car and the car has several different parameters.
Parameters:
Position on map
Altitude (sea level?)
Start position
End Position
Can I use a struct or union (or both?) to have all these parameters inside the car “object” and update the parameters in the object like you would if it was it’s own class in like C++ or Java?
Like if I want to calculate the distance the car traveled from the start position to its current position in like a Cartesian plane I could do something like:
distantTraveled = car.position – car.startPosition
Thanks,
DemiSheep
There are no built-in types that will do what you want.
You’ll probably have to make your own small struct type such as the following.
If you’re limited to C (rather than C++), you’ll then need to build up a small library of functions to operate on these data types.
For what it’s worth, I highly recommend looking around to find a library that will provide this type of thing for you. Ideally something specialized to the domain you’re working in.