vector

Finding vector opposite to another?

I need to know how to find a vector opposite to another, but the second vector is not necessarily the same magnitude as the first, but the direction is opposite. Ex: I made a small diagram :) Basically if I have the coordinates of A(-150,150) and I want B to be opposite, and have a magnitude of only 2, I would want to obtain B(-200,-1...

Data.Vector.Binary overlaps Binary [a] instance

In my application I need to serialize a vector containing an arbitrary datatype, in this case is a list of Doubles. For serializing the vector I'm importing Data.Vector.Binary. When loading the module in GHCi the following error arises: Overlapping instances for Binary [Double] arising from a use of `decode' at Statistics.hs:57:33-42...

Calculating the Moment Of Inertia for a concave 2D polygon relative to its orgin.

Hi, I want to compute the moment of inertia of a (2D) concave polygon. I found this on the internet. But I'm not very sure how to interpret the formula... 1) Is this formula correct? 2) If so, is my convertion to C++ correct? float sum (0); for (int i = 0; i < N; i++) // N = number of vertices { int j = (i + 1) % N; sum += (...

Vector quantization

Hi there, Has anyone heard a way to vector quantize vectors, using opencv ? Thx ...

Add elements and clear a vector of pointers in C++

I would like to add 2 elements to a vector<Node*> and then clear all the elements and release the memory. Does this code do that in a right way? #include <stdlib.h> #include <iostream> #include <vector> using namespace std; class Node { public: int value; // ...and some other fields and methods... }; int main(int argc, char**...

Why is vector<Data*>::iterator valid and vector<Data*>*::iterator not?

I have these three related class members: vector<Frame*>* poolFrames; vector<Frame*>*::iterator frameIterator; vector<vector<Frame*>::iterator>* poolFrameIterators; When I compile, gcc tells me error: invalid use of ‘::’ error: expected ‘;’ before ‘frameIterator’ In reference to the middle line, where I define frameIterators. ...

What is the right way to free a std::vector of pointers in C++?

I searched StackOverflow but couldn't find the answer to this question. Suppose I have a std::vector<Day *> vector_day - that is - a vector of pointers to Day object. Now I push_back to vector_day many elements: vector_day.push_back(new Day(12)); vector_day.push_back(new Day(99)); vector_day.push_back(new Day(71)); ... Now at some po...

General formula to generate a cubic bezier elliptical arc?

How could I implement in C a simple way to generate the 2 missing control points for an elliptic arc given a start and end point? I don't need fancy error estimation, just something that can take points A and D and generate the control points B and C for the elliptical arc where I can then use the cubic bezier interpolation algorithm to ...

How to achieve 'donut holes' with paths in Raphael

I'd like to draw a shape which has holes in it such that I can fill the shape it and not have the holes filled with that colour (leave them transparent). According to the W3 path spec: Compound paths (i.e., a path with multiple subpaths) are possible to allow effects such as "donut holes" in objects. Can somebody please give a ve...

std::vector - Pointer to buffer after reserve()?

I have a std::vector of values for which I know the maximum size, but the actual size will vary during usage: void setupBuffer(const size_t maxSize) { myVector.reserve(maxSize); } void addToBuffer(const Value& v) { myVector.push_back(v); if (myVector.size() == maxSize) { // process data... myVector.clear(); } } Howev...

C++ can't create vector

This is weird. I created a vector just fine in one class but can't create it in another class. He's a representation of what I have: main.h #include <Windows.h> #include <ShellAPI.h> #include <vector> #include <string> #include <iostream> #include "taco.h" class MyClass { public: int someint; vector<int> myOrder; }; taco.h...

Segmentation fault while using priority queues

I have a priority queue with elements of a class named A I need elements from this queue which may be lower down the queue (lesses priority). So , I am trying to pop a few elements until i get the element of my choice. Once i get the element of my choice i am planning to push all the elements i stored temporary in an array. I have a loo...

How to add element by element of two STL vectors?

The question is quite dumb, but I need to do it in a very efficient way - it will be performed over an over again in my code. I have a function that returns a vector, and I have to add the returned values to another vector, element by element. Quite simple: vector<double> result; vector<double> result_temp for(int i=0; i< 10; i++) resul...

C++ 5 dimensional vector ?

I am trying to make a 5 dimensional vector and I can’t seem to get it to work. I know if I need to write a 3 dimensional vector, I could write it in the following way: vector< vector< vector<string> > > block(27, vector< vector<string> > (27, vector<string>(27))); Then I call it: block[x][y][z] = “hello”; I wrote the 5 dimensional v...

Help with this problem?

I'm working on implementing bezier handles into my application. I have points and I need to figure out weather the current direction of the new point is clockwise or counter clockwise. This is because my bezier interpolation algorithm calculates the handles from right to left. Therefore no matter what it interpolates: P1 P1.righthandle ...

C++ Erase vector element by value rather than by position?

vector<int> myVector; and lets say the values in the vector are this (in this order): 5 9 2 8 0 7 If I wanted to erase the element that contains the value of "8", I think I would do this: myVector.erase(myVector.begin()+4); Because that would erase the 4th element. But is there any way to erase an element based off of the value "...

SEGMENTATION FAULT in vector<string> iterator function used to draw text to my self-coded GUI.

Greetings all, ERROR: Program received signal 'SIGSEGV', Segmentation fault. I am having some issues with the following code creating the above fault in Code::Blocks. It is for a chatbox I am using for a network chat program where the vector is filled with the strings of text for each line of the chat log. I don't see why its throwing...

Destructive effects for vector drawings in XAML

There are several applications out there that either allow editing vector graphics in some native format and exporting to XAML format or deal directly in XAML but all of which seem to lack in terms of ability to edit drawings through use of destructive effects. What I mean by destructive effects are ones that can be applied to a vector d...

How do I rotate a polygon in python on a Tkinter Canvas?

Hi, I am working to create a version of asteroids using Python and Tkinter. When the left or right arrow key is pressed the ship needs to rotate. The ship is a triangle on the Tkinter canvas. I am having trouble coming up with formula to adjust the coordinates for the triangle. I believe it has something to do with sin and cos, though I...

C++ - Sort multidimensional vector by its contained object property

Hi guys, I've got a bidimensional array of objects (a 2D vector containing GridCell instances) as in here: typedef vector<GridCell> CellArray; typedef vector<CellArray> TwoDCellArray; TwoDCellArray CellArr2D; I am currently drawing all the cells like this: for (int i = 0; i < rows; i++){ for (int j = 0; j < cols; j++){ C...