vector

Questions about vector, union, and pointers in c++

The question I have are NOT homework questions, but I am considering using these concepts in my assignment. The content,if it helps, is like this: I need to keep track of several union instances and they belong to my own union in one of my own class as class variables. (Note: the number of union instance is unknown, so I cannot just have...

Calculate direction vector

HI All, How can I calculate direction vector of a line segment, defined by start point (x1, y1) and end point (x2, y2)? Cheers. ...

What is the element value in an uninitialized vector?

If I create a vector like vector<myClass> v(10); what is the default value of each element? Also, what if it is a vector<myUnion> v(10) ? ...

what is the capacity of an empty vector?

Looks like a stupid question. But comment to my answer to one of the SO question made me to think again. [ comment says, capacity need not be zero for empty vector] By default my answer would be 0 as there are no elements inside vector. It makes sense to keep the capacity as 0 and on the first allocation it can be increased without an...

A colleague said don't use java.util.Vector anymore - why not?

Previously I would always have thought a Vector was good to use for non-descript objects when length was unknown. As far as I was aware I thought it was thread-safe too What would change that it shouldn't be used anymore, and what is the alternative? ...

2D vector to 3D vector

Hi guys I'm trying to make a circle across a plane using sin and cos. While it works all well when its aligned with the x, y, or z axis, I need something more dynamic. Is there any way to transform a 2D vector to a 3D one using a plane normal, or perhaps another solution? Thanks in advanced. ...

c++ vector of class object pointers

Hi all, What I am trying to do is essentially create two vectors of objects, where some objects are entered into both lists and some are just entered into one. The first problem I found was that when I used push_back() to add an object into both lists the object was copied so that when I changed it from one list the object did not chang...

Given a start and end point, and a distance, calculate a point along a line

Looking for the quickest way to calculate a point that lies on a line a given distance away from the end point of the line: void calculate_line_point(int x1, int y1, int x2, int y2, int distance, int *px, int *py) { //calculate a point on the line x1-y1 to x2-y2 that is distance from x2-y2 *px = ??? *py = ??? } Thanks fo...

Modifying contents of vector in BOOST_FOREACH

This is a question that goes to how BOOST_FOREACH checks it's loop termination cout << "Testing BOOST_FOREACH" << endl; vector<int> numbers; numbers.reserve(8); numbers.push_back(1); numbers.push_back(2); numbers.push_back(3); cout << "capacity = " << numbers.capacity() << endl; BOOST_FOREACH(int elem, numbers) { cout << elem << end...

Is there a version of the removeElement function in Go for the vector package like Java has in its Vector class?

I am porting over some Java code into Google's Go language and I converting all code except I am stuck on just one part after an amazingly smooth port. My Go code looks like this and the section I am talking about is commented out: func main() { var puzzleHistory * vector.Vector; puzzleHistory = vector.New(0); var puzzle Peg...

Runtime error: Access violation when using .push_back() with a std::vector?

I have a vector, defined by std::vector<LPDIRECT3DTEXTURE9> textures; Later, I am passing a LPDIRECT3DTEXTURE9 object to it, like so textures.push_back(texture); Here is a sample of this: void SpriteManager::AddSprite(float x, float y, float z, LPDIRECT3DTEXTURE9 texture) { //snip textures.push_back(texture); //snip } Th...

How to store a vector of LPD3DXSPRITE objects?

Let's say I want to store a vector of LPD3DXSPRITE objects. The line to declare this code would be std::vector<LPD3DXSPRITE> sprites; I should be able to create my sprite with: LPD3DXSPRITE sprite = NULL; D3DXCreateSprite(myRenderingDevice, &sprite); Finally, I should be able to add this to the vector like so: sprites.push_back(spr...

Suppose I have 2 vectors. What algorithms can I use to compare them?

Company 1 has this vector: ['books','video','photography','food','toothpaste','burgers'] ... ... Company 2 has this vector: ['video','processor','photography','LCD','power supply', 'books'] ... ... Suppose this is a frequency distribution (I could make it a tuple but too much to type). As you can see...these vectors have things tha...

Are vector assignments copied by value or by reference in Google's Go language?

In the following code, I create one peg puzzle then do a move on it which adds a move to its movesAlreadyDone vector. Then I create another peg puzzle then do a move on it which adds a move to its movesAlreadyDone vector. When I print out the values in that vector for the second one, it has the move in it from the first one along with th...

Text alignment in SVG

How to make text with proportional font but an equal number of characters per line fully justified in SVG text box? Preferably with an svg-code example if it's possible. ...

How to move OpenLayers Vector programmatically?

The API documentation for OpenLayers.Feature.Vector says that Vector itself has no methods at all. I know how to let user move the Vector by adding OpenLayers.Control.DragFeature control to map. So if the user can move the Vector then there has to ba a way to move it programmatically too. But I can't figure out how to do it. ...

Java: Setting array length for an unknown number of entries

I am trying to fill a RealVector (from Apache Commons Math) with values. I tried using the class's append method, but that didn't actually add anything. So now I'm using a double[], which works fine, except I don't know in advance how big the array needs to be. private void runAnalysis() throws IllegalArgumentException, IllegalAccessExc...

Calculating point of intersection based on angle and speed

I have a vector consisting of a point, speed and direction. We will call this vector R. And another vector that only consists of a point and a speed. No direction. We will call this one T. Now, what I am trying to do is to find the shortest intersection point of these two vectors. Since T has no direction, this is proving to be difficult...

Java Error using Vectors: unchecked call to add(E)

Offending bit of code Vector moves = new Vector(); moves.add(new Integer(x)); Error: ConnectFour.java:82: warning: [unchecked] unchecked call to add(E) as a member of the raw type java.util.Vector moves.add(new Integer(x)); Not really sure how much info is needed for an error like this.... ...

[Matlab] Storing Results of a Operation in a Matrix

Let's say I want to take the sin of 1 through 100 (in degrees). I come from a C background so my instinct is to loop 1 through 100 in a for loop (something I can do in Matlab). In a matrix/vector/array I would store sin(x) where x is the counter of the for loop. I cannot figure out how to do this in Matlab. Do I create a array like ...