vectors

How to declare vectors in C++ ?

Hi, I'm trying to use a vector of strings in my code instead of an array of strings but apparently I miss some detail in the declaration of the vector. Using the following code, I get this error: ‘vector’ was not declared in this scope // Try to implement a vector of string elements #include<iostream> using namespace std; int main() ...

Generating vectors in MATLAB

Hi. I am wondering whether there is an efficient way in MATLAB to generate all vectors of a fixed length with elements from a finite set. For instance, how can I build all vectors of length 5 with only 0 or 1 as elements? ...

How to navigate through a vector using iterators? (C++)

The goal is to access the "nth" element of a vector of strings instead of the [] operator or the "at" method. From what I understand, iterators can be used to navigate through containers, but I've never used iterators before, and what I'm reading is confusing. If anyone could give me some information on how to achieve this, I would appr...

String vectors not working as expected with newline and iterators? (C++)

I have a text file made of 3 lines: Line 1 Line 3 (Line 1, a blank line, and Line 3) vector<string> text; vector<string>::iterator it; ifstream file("test.txt"); string str; while (getline(file, str)) { if (str.length() == 0) str = "\n"; // since getline discards the newline character, replacing blank strings with newline ...

Python Vector Class

I'm coming from a C# background where this stuff is super easy—trying to translate into Python for Maya. There's gotta' be a better way to do this. Basically, I'm looking to create a Vector class that will simply have x, y and z coordinates, but it would be ideal if this class returned a tuple with all 3 coordinates and if you could edi...

How do I get characters common to two vectors in C++?

I am trying to compare two vector objects, and return a single vector containing all the chars which appear in both vectors. How would I go about this without writing some horribly complex manual method which compares every char in the first vector to every char in the second vector and using an if to add it to a third vector (which wou...

Cartesian product of several vectors

Hi, similar questions have been asked before but I cant find an exact match to my question. I have 4 vectors each of which hold between 200-500 4 digit integers. The exact number of elements in each vector varies but I could fix it to a specific value. I need to find all possible combinations of the elements in these 4 vectors. eg: ...

Calculating the perpendicular plane to a triangle in 3D space

This is somewhat hard to describe, so bare with me. Essentially I have a triangle in 3D space defined by its 3 vertices, p0, p1, and p2. I wish to calculate a plane in this 3D space which lies along both p0 and p1 and faces a third point, p2. This plane is to be defined by a position and normalised direction/ In addition to lying al...

Finding the 'foot' of an altitude of a triangle in 3D space

A little backstory, currently I'm working on implementing a triangle rendering system in Expression2 to create .obj models. One of the limitations I'm currently experiencing is that I cannot create polygons the old-fashioned way, rather, I'm having to create Isosceles triangles, and cut part of it off. My current problem is that I'm ...

Create a re-sizable array of CGPoints in objective-c

Hi I am trying to create a re-sizable array of CGPoints in objective-c. I've have looked into using NSMutableArray however it doesnt seem to allow resizing. Is there something else I can use? thank you ...

Visualisation of star catalogues and celestial coordinates

Does anyone have a suggested methodology for visualising the data in a star catalogue such as the Bright Star Catalogue. I'm thinking that there would be a notional sphere and a viewpoint i.e. at the center of that sphere with two vectors representing the view direction and view horizons. I would then somehow project from the star cata...

How do you calculate the reflex angle given to vectors in 3D space?

I want to calculate the angle between two vectors a and b. Lets assume these are at the origin. This can be done with theta = arccos(a . b / |a| * |b|) However arccos gives you the angle in [0, pi], i.e. it will never give you an angle greater than 180 degrees, which is what I want. So how do you find out when the vectors have gone pa...

Adding multiple vectors in R

I have a problem where I have to add thirty-three integer vectors of equal length from a dataset in R. I know the simple solution would be Vector1 + Vector2 + Vector3 +VectorN But I am sure there is a way to code this. Also some vectors have NA in place of integers so I need a way to skip those. I know this may be very basic but I am ...

Method for combining tiled squares defined as points into vectors

If I tile squares, and the squares can be defined by their coordinates, how can I simplify shapes made of multiple squares into vectors that define each edge of the entire shape? Pseudo-code or general terms are fine. ...

Calculate direction angle from two vectors?

Hi, Say I have two 2D vectors, one for an objects current position and one for that objects previous position. How can I work out the direction of travel? This image might help understand what I'm after: Thanks -James ...

Vectors of Pointers, inheritance

Hi I am a C++ beginner just encountered a problem I don't know how to fix I have two class, this is the header file: class A { public: int i; A(int a); }; class B: public A { public: string str; B(int a, string b); }; then I want to create a vector in main which store either class A or class B vect...

Do classes which have a vector has a member have memory issues

I am just starting out C++, so sorry if this is a dumb question. I have a class Braid whose members are vectors. I have not written an assignment operator. When I do a lot of assignments to an object of the type Braid, I run into memory issues :- 0 0xb7daff89 in _int_malloc () from /lib/libc.so.6 #1 0xb7db2583 in malloc () from /lib/...

Game enemy move towards player

I'm creating a game in c++ and OpenGL and want an enemy to move towards the player. What is the best method of making game objects move towards other game objects, that works in both 2D and 3D game environments? UPDATE: wow thanks everyone for the quick replies! strangely enough I managed to get this to work just as I posted it alth...

How to create a function with vectors and vertical asymptote using MATLAB

Plot the function f(x) = 1.5x / x-4 for -10 equal or less than X equal or less than 10. Notice that the function have a vertical asymptote at x = 4. Plot the function by creating two vectors for the domain of x. The first vector (call it x1) with elements from -10 to 3.7, and the second vector (calle it x2) with elements from 4.3 to 10. ...

C++ iterators problem

I'm working with iterators on C++ and I'm having some trouble here. It says "Debug Assertion Failed" on expression (this->_Has_container()) on line interIterator++. Distance list is a vector< vector< DistanceNode > >. What I'm I doing wrong? vector< vector<DistanceNode> >::iterator externIterator = distanceList.begin(); while (exter...