vector

Interpolate x, y, z coordinates on a sphere using points from two spin vectors?

I want to plot 3D points in real time that lie upon the surface of a unit sphere (r = 1). There are two spin vectors at work here. One vector rotates around the Y axis, it's X and Z values are calculated using the cos() and sin() of a circle that lies completely on the X/Z plane with all Y values being equal to 0. The other rotates ...

Vector quantization & LBG

Hi there, In the purpose of vector quantization, I'm using the linde-buzo-gray (LBG) algorithm to generate the codebook. To generate 256 codewords in this codebook, I'm using 256 000 training vectors (all of 128 dimensions). This codebook is initialized with a vector and than split until obtaining 256 codewords. My problem is : at th...

vector resize() automatic fill

Hi everyone, I'm writing a class that holds a matrix (of double values), represented as vector<vector<double>>; I want to implement the operator=, to re-fill my matrix with the details of a given sparse matrix. I'm writing the following code: RegMatrix& RegMatrix::operator=(const SparseMatrix rhs){ if(*this != rhs){ _matri...

Is a std::vector pointer reliable?

Say I have this: Object *myObject; std::vector<Object> objects(99); .... myObject = &objects[4]; Would it be safe to assume that myObject's pointer will always be valid no matter how big objects[] gets and if I remove some, as long as I do not ever erase() the actual object pointed to by myObject? Or does it work differently? If the ...

Help with this (pointers and polymorphism)

Here is my issue. I'm creating my own GUI Api. All the Widgets are in a container which has add and remove functions. The widgets derive from a base widget class. Here is where I'm unsure. I would ideally like a flow like this: user creates a (desired widget deriving from base class) pointer, the container allocates and manages resources...

How to apply DOP and keep a nice user interface?

Hello coders out there! Currently I want to optimize my 3d engine for consoles a bit. More precisely I want to be more cache friendly and align my structures more data oriented, but also want to keep my nice user interface. For example: bool Init() { // Create a node ISceneNode* pNode = GetSystem()->GetSceneManager()->AddNode("vie...

C++ vector of vectors

Hey everyone! I am trying to write a program that uses a base class to define an algorithm for solving a simple problem. I use a vector of ints as a 'game board'. My question is how can I create a function get_moves that returns a vector of game boards? Here is the code I have for the function: std::vector< <std::vector<int> > takeawa...

is it possible to return two vectors from a function?

Im trying to do a merge sort in cpp on a vector called x, which contains x coordinates. As the mergesort sorts the x coordinates, its supposed to move the corresponding elements in a vector called y, containing the y coordinates. the only problem is that i dont know how to (or if i can) return both resulting vectors from the merge functi...

How do I rotate vectors using matrices in Processing ?

I am trying to rotate vectors using matrices, but got confused. I thought all I needed to do is create a rotation matrix and multiply it to a vector to get the rotated vector. Here you can see a simple test I've done using Processing: Use a to increment rotation, and x/y/z to changes the axis. And here is source: PVector[] clone,f...

Matlab - how to replace all the special characters in a vector?

Hi, Is it possible to replace all the special characters in a matlab vector through a regular expression? Thank you *EDIT: * Thank you for your responses. I'm trying to achieve the following. I have a text file that contains few paragraphs from a novel. I have read this file into a vector. fileText = ['Token1,' 'token_2' 'token%!3'...

c++ multiply vector elements by a scalar value using STL

Hi I want to (multiply,add,etc) vector by scalar value for example myv1 * 3 , I know I can do a function with a forloop , but is there a way of doing this using STL function ? something like the {Algorithm.h :: transform function } ?? ...

Problematic vector return value - not really updated?

I'm having this weird problem: when my program reach this method: //Returns the transpose matrix of this one RegMatrix RegMatrix::transpose() const{ RegMatrix result(numCol,numRow); int i,j; for(i=0;i<numRow;++i) for(j=0;j<numCol;++j){ result._matrix[j][i] = _matrix[i][j]; } return result...

Converting arrays in stl like copy

Hi everybody! It's time for another 'how do i do this in c++ without loosing my grip'-question! This time: Considering the following code taken from cplusplus.com: template<class InputIterator, class OutputIterator> OutputIterator copy ( InputIterator first, InputIterator last, OutputIterator result ) { while (first!=last) *resul...

Erasing an element from the vector during iteration c++

Hi, I wrote this method to find the minor of a sparse matrix: SpMatrixVec SparseMatrix::minor(SpMatrixVec matrix, int col) const{ SpMatrixVec::iterator it = matrix.begin(); int currRow = it->getRow(); int currCol = col; while(it != matrix.end()) { if(it->getRow() == currRow || it->getCol() == currCol){ ...

c++ cast vector<Inherited*> to vector<abstract*>

Hi! class Interface{}; class Foo: public Interface{}; class Bar{ public: vector<Interface*> getStuff(); private: vector<Foo*> stuff; }; how Do I implement the funtion getStuff() ? hope the question is clear.. Thanks! ...

SVG embed bug in Safari forces me to look for another option.

Hi, I'm building an interactive website for a touchscreen, which runs the latest version of Google Chrome. The user has to tap on, in this case, a series of buildings to get more information about it. The idea is to absolute position hyperlinks and place them on top of the buildings, which are combined in a single background image. But ...

Determining the edge normals in the SAT Separating Axis Theorem

The SAT algorithm requires you to find the normal of each edge of each shape (essentially a vector perpendicular to the edge vector) to be used as the separating axes. This can be done very simply... (x,y) => (-y,x) OR (x,y) => (y,-x) Which should be used in the SAT algorithm? This is essentially a question of whether the left hand n...

How can I find the rotation of a quad in 3D ?

I have coordinates for 4 vectors defining a quad and another one for it's normal. I am trying to get the rotation of the quad. I get good results for rotation on X and Y just using the normal, but I got stuck getting the Z, since I've used just 1 vector. Here's my basic test using Processing and toxiclibs(Vec3D and heading methods): im...

Deep copy of vector<Point> myArr

In order to make a deep copy of myArr, vector <Point> myArr; where Point is a class with 2 ints as members, Do I need to do something special? or is ok with vector <Point> otherArr = myArr; I need to delete some points in otherArr but at the same time I need all the points in myArr for later usage. thanks in advance ...

C++ Storing copy of string in vector of pairs

I have a private attribute in a class that is defined as vector<pair<char *, int> > data;. I add data to this vector with data.push_back(make_pair(p, r));. Later when I go to get the data out of the vector I get bad data for the p value. The data returned is like ��U3. I think this is because a pointer to the char array is being stored. ...