vectors

Is it safe to assume that STL vector storage is always contiguous?

If you have an STL vector which has been resized, is it safe to take the address of element 0 and assume the rest of the vector will follow in memory? e.g. vector<char> vc(100); // do some stuff with vc vc.resize(200); char* p = &vc[0]; // do stuff with *p ...

Using arrays or std::vectors in C++, what's the performance gap?

In our C++ course they suggest not to use C++ arrays on new projects anymore. As far as I know Stroustroup himself suggests not to use arrays. But are there significant performance differences? ...

Projecting a screen for a camera

I'm trying to learn a little more on vectormath through writing a simple ray tracer and I've been doing some reading on it, but what I haven't been able to find is how to determine the direction of the primary rays. This sounds like a simple problem and probably is, but with my current knowledge I haven't been able to figure it out. I ...

What are vectors and how are they used in programming?

I'm familiar with the mathematical/physics concept of a vector as a magnitude and a direction, but I also keep coming across references to vectors in the context of programming (for example C++ seems to have a stl::vector library which comes up fairly frequently on SO). My intuition from the context has been that they're a fairly primit...

Subtracting 2 lists in Python

Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like [2,2,2] - [1,1,1] = [1,1,1] Should I use tuples? If none of them defines these operands on these types, can I define it instead? If not, should I create a new vector3 class? ...

How do I calculate the average direction of two vectors

Hi, I am writing and opengl based iphone app and would like to allow a user to translate around a view based on the direction that they move two fingers on the screen. For one finger I know I could just calculate the vector from the start position to the current position of the users finger and then find the unit vector of this to get j...

Vectors, structs and std::find

Again me with vectors. I hope I'm not too annoying. I have a struct like this : struct monster { DWORD id; int x; int y; int distance; int HP; }; So I created a vector : std::vector<monster> monsters; But now I don't know how to search through the vector. I want to find an ID of the monster inside the vector. ...

How can I access variables in vector<struct> *obj?

How would I get my variables out of a vector? I can't use the binary insertion operators or the equal operators. Earlier, I declared a vector<someStruct> *vObj and allocated it, then returned the vObj and called it in this function: vector<sameStruct> firstFunc(); for (unsigned int x = 0; x < v->size(); x++) { v[x]; } when I deb...

C++ vector literals, or something like them

I'm writing some code against a C++ API that takes vectors of vectors of vectors, and it's getting tedious to write code like the following all over the place: vector<string> vs1; vs1.push_back("x"); vs1.push_back("y"); ... vector<string> vs2; ... vector<vector<string> > vvs1; vvs1.push_back(vs1); vvs1.push_back(vs2); ... vector<vector<...

Is there a Vector3 type in Python?

I quickly checked numPy but it looks like it's using arrays as vectors? I am looking for a proper Vector3 type that I can instance and work on. ...

C++ question... definition doesn't recognize vectors specified in declaration

I'm working on a class assignment that started small, so I had it all in one file. Now it's gotten bigger and I'm trying to separately compile main, functions, and classes (so all the classes are together in one .h and one .cpp) I have one class B, which is the parent of a lot of others and comes first in the file. One of its data member...

Does Berkeley DB java edition, support saving vectors

I am getting the following stack trace. Just want to know what your first impression is. Does it seem to be saying that Vectors cannot be saved to the Berkeley DB. What else can I provide you with, that will help work this out. Exception in thread "Timer-0" java.lang.IllegalArgumentException: Class could not be loaded or is not persiste...

C++ memory management and vectors

Hi All, I'm getting very confused with memory management in relation to vectors and could do with some basic concepts explaining. I have a program that uses big vectors. I created the vectors with the new operator and release them at the end of the program with delete to get the memory back. My question is, if the program crashes or ge...

Difference between Vector, Set, and Tuple

As the title says, what is the differences between vectors, sets, and tuples in programming? ...

Can WPF render a line path with 300,000 points on it in a performance-sensitive environment?

A simple XY line graph: The X axis will represent the complete range of possible rating percentages, from 0% on one end to 100% on the other. Specifically, the X value will represent our rating cut-off, or the minimum rating a transaction can have before it is no longer acceptable. The Y axis will show values from 0 to the total number o...

Rotate normal vector onto axis plane

I have a set of data points in 3D space which apparently all fall onto a specific plane. I use PCA to compute the plane parameters. The 3rd component of PCA gives me the normal vector of the plane (weakest component). What I want to do next is to transform all the points onto said plane and look at it in 2D. My idea was to do the foll...

Vector to Matrix syntax in MATLAB...

Is there a way to combine 2 vectors in MATLAB such that: mat = zeros(length(C),length(S)); for j=1:length(C) mat(j,:)=C(j)*S; end Using normal MATLAB syntax similar to: mat = C * S(1:length(S)) This gives a "Inner matrix dimensions must agree error" because it's trying to do normal matrix operations. This is not a standard Lin...

Finding quaternion representing the rotation from one vector to another

I have two vectors u and v. Is there a way of finding a quaternion representing the rotation from u to v? ...

Capturing print output as vector format (PDF,SVG,EMF,etc.)

BACKGROUND I am using a commercial application on windows that creates a drawing This application allows only two output options: (1) save as a bitmap file and (2) print to a printer the bitmap is useless for my purposes - I want the vectors Looking at the print output (I sent to the Windows XPS print driver) it seems clear based on th...

Programmatically creating vector arrows in KML

Does anyone have any practical examples of programmatically drawing icons as vectors in KML? Specifically, I have data with a magnitude and an azimuth at given coordinates, and I would like to have icons (or another graphical element) generated based on these values. Some thoughts on how I might approach it: Image directory (a brute f...