vector

Help with connected outlines

I'm making a vector drawing application. I use this algorithm to generate outlines. This algorthm works well, except it does not close the outline as seen here: I'm not sure what I should do to ensure that it always closes the outline. I tried inserting the last vertex at position[0] in the std::vector but this did not help. DOUBLEPO...

Rounding the start and end of an outline

I use the following algorithm to generate polygon outlines: void OGLSHAPE::GenerateLinePoly(std::vector<DOUBLEPOINT> &input, int width) { OutlineVec.clear(); if(input.size() < 2) { return; } if(connected) { input.push_back(input[0]); input.push_back(input[1]); } float w = width...

Finding the vector between 2 vectors (2D)

Lets say for example I have the following 2 vectors: *B *A The vector I would want would be C *C *B *A What I'm trying to do is generate square outlines. I use 2d slurp: where v0 would be A and v2 would be B. Right now I use sslerp2D to make round edges but I also want regular square edges hence why I want to...

draw 3d faces as 2d

I have 3d mesh and I would like to draw each face a 2d shape. What I have in mind is this: for each face 1. access the face normal 2. get a rotation matrix from the normal vector 3. multiply each vertex to the rotation matrix to get the vertices in a '2d like ' plane 4. get 2 coordinates from the transformed vertices I don't know if th...

::std::vector::at() vs operator[] << surprising results!! 5 to 10 times slower/faster!

During program optimization, trying to optimize a loop that iterates through a vector, I found the following fact: ::std::vector::at() is EXTREMELY slower than operator[] ! The operator[] is 5 to 10 times faster than at(), both in release & debug builds (VS2008 x86). Reading a bit on the web got me to realize that at() has boundary che...

How do vector applications skew polygons?

I know how to move, rotate, and scale, but how does skewing work? what would I have to do to a set of verticies to skew them? Thanks ...

Distorting a polygon (Like Photoshop's distort) (Perspective Transformation)

In Photoshop there is a tool that allows the selection to be "Distorted". This allows easy shadow creation among other things. How could this sort of distortion be applied for a polygon (a bunch of points)? Thanks ...

Perspective and Bilinear transformations

I'm making a vector drawing application and noticed that Anti Grain Geometry have an example that does exactly what I want. http://www.antigrain.com/demo/index.html then below there is an example on perspective for Win32. I don't understand their cpp file. Based on this example. If I have a bunch of verticies to form an object, like thei...

Convert vector<char> buf(256) to LPCSTR?

Is there a way to convert the above? If so what is the best way? I guess you can loop through the vector and assign to a const char*, but I'm not sure if that is the best way. ...

Perform vector operation

Hi, I'm using the vector container to store an array of doubles. Is there any quick way of multiplying each element in my vector by some scalar without using a loop. For example: vector<double> Array(10,1); will initialise an array of 10 doubles with initial value 1. To multiply this array by 0.5 I would write: for(unsigne...

Standard predicates for STL count_if

Hi, I'm using the STL function count_if to count all the positive values in a vector of doubles. For example my code is something like: vector<double> Array(1,1.0) Array.push_back(-1.0); Array.push_back(1.0); cout << count_if(Array.begin(), Array.end(), isPositive); where the function isPositive is defined as bool isPosit...

cumulative sum for a vector of doubles

Hi, I have a vector of doubles and I need to create another array which is a cumulative sum of the elements of the first. For example; vector<double> Array(10,1); vector<double> Sum(10); Sum[0] = Array[0]; for(unsigned int i=1; i<Array.size(); i++) Sum[i] = Sum[i-1] + Array[i]; Is there an in-built function that will ...

Advice needed: A programmatic way for creating vector graphics with heavy usage of text.

I need a way for render a tree-like structures, similar to flowcharts. Surprisingly, I can't find(or I'm doing wrong) a suitable tool. First, I looked at SVG. But I couldn't find a way to draw a bounding box around the text without using ECMAScript: I tried to do a simple thing drawing two text surrounded by boxes and linked by a lin...

square-root and square of vector doubles in C++

Hi, I'd like to calculate the square and square-root of a vector of doubles. For example given: vector<double> Array1(10,2.0); vector<double> Array2(10,2.0); for(unsigned int i=0; i<Array1.size(); i++) Array1[i] = sqrt(Array1[i]); for(unsigned int i=0; i<Array2.size(); i++) Array2[i] = Array2[i] * Array2[i]; Is the...

C++ append one vector to another

I fully understand this question has been asked a lot, but I'm asking for a specific variation and my search-foo has given up, as I've only found algorithms that append one existing vector to another, but not one returned to from a function. I have this function that lists all files in a directory: vector<string> scanDir( const string&...

How to move a line ? xcode

Hi all, Would appreciate any ideas. I have a line (begin x,y / end x,y). Its stored in an array. I can detect a touch that intersects my line (can delete etc; from array). What I would like to do now is to move that line to new location (based on drag), or, continue the line further (or indeed reduce its length) at either point. All base...

Slicing problem?

g++ -std=gnu++0x main.cpp In file included from main.cpp:6:0: CustArray.h: In constructor 'CustArray::CustArray()': CustArray.h:26:32: error: 'class Info' has no member named 'someInfo' make: *** [all] Error 1 /* * Info.h * */ #ifndef INFO_H_ #define INFO_H_ class Info { friend class CustArray; }; #endif /* INFO_H_ */ /* * ...

Split a vector into chunks in R

Hi, I have to split a vector into n chunks of equal size in R. I couldn't find any base function to do that. Also Google didn't get me anywhere. So here is what I came up with, hopefully it helps someone some where. x <- 1:10 n <- 3 chunk <- function(x,n) split(x, factor(sort(rank(x)%%n))) chunk(x,n) $`0` [1] 1 2 3 $`1` [1] 4 5 6 7 ...

How could this be done?

Given the following path: How could these smooth curves be generated given that the user provides the points and that cubic bezier is used? How would the control points or bezier handles be solved for, or how could I compute these points using cubic bezier given the user points above (the red squares) ? Basically I have an algorithm to...

Seg fault vector<vector<list<Object*> > > push_back

I have a 3D vector defined like this... std::vector<std::vector<std::list<Object*> > > m_objectTiles; I have this code... void ObjectManager::AddObject( Object *object ) { m_objects.push_back( object ); m_objectTypes.insert( std::make_pair( ObjectAttorney::GetType( object ), object )); int x = ObjectAttorney::GetTileX( ob...