vector

Determine the general orientation of a 2D vector

Hi everyone, I have a rather simple question for you.. I feel like I should have found the answer a long time ago but somehow I can't wrap my head around this trivial problem. Given a vector v = (x,y) , I would like to know it's 'general' orientation. That is either 'Up', 'Down', 'Left' or 'Right' A vector's general orientation is 'Up'...

Is there a way to export a DisplayObject's vector data?

Flex gives the ability to export a display object as a bitmap as follows: var bitmapDataBuffer:BitmapData = new BitmapData ( displayObject.width, displayObject.height, false); bitmapDataBuffer.draw ( displayObject, displayObject.transform.matrix); Is there a method to export a display object as a vector graphic instead of ...

manipulation of Vectors created with new

Can anyone help with this... vector<unsigned int> *vVec = new vector<unsigned int>; vVec .reserve(frankReservedSpace); start = std::clock(); for(int f=0; f<sizeOfvec; f++) { //Populate the newly created vector on the heap vVec .push_back(pArray[f]); } I'm getting: error C2228: left...

Why is the beginning of my string disappearing?

In the following C++ code, I realised that gcount() was returning a larger number than I wanted, because getline() consumes the final newline character but doesn't send it to the input stream. What I still don't understand is the program's output, though. For input "Test\n", why do I get " est\n"? How come my mistake affects the first...

Clojure Vector of Refs

What's the simplest way to create a vector of distinct refs? Using (repeat 5 (ref nil)) will return a list, but they will all reference the same ref: user=> (repeat 5 (ref nil)) (#<Ref@16ef71: nil> #<Ref@16ef71: nil> #<Ref@16ef71: nil> #<Ref@16ef71: nil> #<R ef@16ef71: nil>) Same result with (replicate 5 (ref nil)): user=> (replicat...

Most efficient way to erase duplicates and sort a c++ vector?

I need to take a C++ vector with potentially a lot of elements, erase duplicates, and sort it. Looks like this code will do the trick: (Correction--it won't; next time I'll test before posting. Thanks for the feedback.) vec.erase( std::unique(vec.begin(), vec.end()), vec.end()); std::sort(vec.begin(), vec.end()); Is it f...

Search an attribute inside a Vector on Java

I've a Vector of objects, and have to search inside for a random attribute of those objects (For example, a Plane class, a Vector containing Plane; and I've to search sometimes for destination, and others to pilotName). I know I can traverse the Vector using an Iterator, but I've got stuck at how do I change the comparison made between ...

What if I increment an iterator by 2 when it points onto the last element of a vector?

In this question asking how to adjust the iterator to an STL container by 2 elements two different approaches are offered: either use a form of arithmetic operator - +=2 or ++ twice or use std::advance() I've tested both of them with VC++ 7 for the edge case when the iterator points onto the last element of the STL container or beyon...

How to normalize a vector in MATLAB efficiently? Any related built-in function ?

I normalize a vector V in MATLAB as following: normalized_V = V/norm(V); however, is it the most elegant (efficient) way to normalize a vector in MATLAB? ...

How does the C++ STL vector template store its objects in the Visual Studio compiler implementation?

I am extending the Visual Studio 2003 debugger using autoexp.dat and a DLL to improve the way it displays data in the watch window. The main reason I am using a DLL rather than just the basic autoexp.dat functionality is that I want to be able to display things conditionally. e.g. I want to be able to say "If the name member is not an em...

What to do when java.util is missing on a Mac

This is kind of weired but my Mac/Eclipse isn't offering me any java.util classes. I am still able to run the project which contains heavy use of (let's say) Vector, but I am not able to add a new Vector in the code anywhere. Eclipse isn't offereing me... I spent the last night reconfiguering the installed JRE's and build path etc. but...

What is the ideal growth rate for a dynamically allocated array?

C++ has std::vector and Java has ArrayList, and many other languages have their own form of dynamically allocated array. When a dynamic array runs out of space, it gets reallocated into a larger area and the old values are copied into the new array. A question central to the performance of such an array is how fast the array grows in siz...

Group sorting a vector in C++

I have a std::vector full of objects, each with a numeric group identifier associated with them. The object also has properties such as "size" and "name". I need to be able to sort the vector of objects by name, size and other properties while keeping them grouped together (e.g. by the group identifier mentioned above). How can this go...

AS3: How to convert a Vector to an Array

What's the nicest way to convert a Vector to an Array in Actionscript3? The normal casting syntax doesn't work: var myVector:Vector.<Foo> = new Vector(); var myArray:Array = Array(myVector); // calls the top-level function Array() due to the existance of the Array function. The above results in an array, but it's an array with a sin...

reduce the capacity of an stl vector

Hi, Is there a way to reduce the capacity of a vector ? My code inserts values into a vector (not knowing their number beforehand), and when this finishes, the vectors are used only for read operations. I guess I could create a new vector, do a .reseve() with the size and copy the items, but I don't really like the extra copy operati...

How to create an array of string vectors in Java ?

I use the following code try to create an array of string vectors, I hope to have an array of 3 items, each item is a string vector : Vector<String> Result_Vector_Array[]=new Vector<String>[3]; But NB highlighted the line as error(generic array creation), what's wrong ? What's the correct way to do it ? I know there is also Arraylist,...

J2ME Get Specific Object from Vector

Currently I'm implementing a Persistant Storage Object for my Blackberry Application. It contains a Vector of Setting Objects. My current implemention to get specific settings value looks like this public String getSettingByName(String key) { String value = ""; for ( Enumeration e = _appSettings.elements(); e.hasMoreElements();) ...

Java Convert Object[] Array to Vector

What's the best way to convert an Object array to a Vector? JDE < 1.5 public Vector getListElements() { Vector myVector = this.elements; return myVector; } this.elements is an Object[] Thanks, rAyt I should clarify my question My target platform is a blackberry. Collections aren't supported. Array.asList() isn't, either :/ F...

how to sort numeric vectors?

Now, there are lots of ordered numeric vectors(about 50 dimension). Each dimension is a integer between 0~200. I want to sort them to ensure the similar vectors in the same bucket, all vectors in adjacent buckets have also a similarity to a certain extent. e.g. <1,24,25,78,9> and <2,24,24,78,9> should be in same bucket(bucket number is 0...

Calculating 'up vector' from transformation matrix in 3D

Hello! I just came to strange problem with my project in 3D. Everyone knows algorythm of calculating LookAt vector, but it is not so easly to calculate "up" vector from transformation matrix (or at least maybe I simple missed something). The problem is following: "Up" vector is (0, 1, 0) for identity rotation matrix and rotate with ma...