C++ Make array/linked list with different class objects - c++

I am wildly searching the net and this site in order to understand how to do what I want to do. And while there is tons of search results I am not sure if I really understand how to do this (I am fairly new to C++). So my hope is that I get some help here.
What I want to do:
I want to create a contour of geometric segments, e.g. a line segment, followed by a circular arc segment, followed by three lines, followed by whatever may come. The order and definition of each segment composing the contour can vary from execution to execution.
The geometric items have already been created. Now I want to put them together. I am entirely uncertain which way to adopt:
My first idea was to use a linked list, since later I want to go through each segment in the same order (so not jumping from 3rd segment to 9th segment back to 5th segment).
1a) How can I implement that provided that the classes for each segment are very different.
1b) How can I access a specific element? Would I need to define an id number for each list member and then walk thru the list until I reach that id number?
More comfy would be probably an array. But I still don't understand how to do this properly.
Would be awesome if somebody here could indicate how to approach this. Thanks!
Here are the simplified classes that I am dealing with (circle is here representing the circular arc):
struct point {
double x;
double y;}
class Line
{
public:
Line(const point pt1, const point pt2)
{
P1.x = pt1.x;
P1.y = pt1.y;
P2.x = pt2.x;
P2.y = pt2.y;
}
~Line() {};
double get_length() { return calc_length(); }
double get_angle() { return angle; }
private:
point P1;
point P2;
double calc_length()
{
// calculate length (here: dummy value)
length = 1;
}
double calc_angle()
{
// calculate angle (here: dummy value)
angle = 0.5;
}
double length = 0;
double angle = 0;
}
class circle
{
public:
circle(const double r, const point c)
{
radius = r;
center.x = c.x;
center.y = c.y;
}
~circle() {};
double get_radius() { return radius; };
point get_center() { return center; };
double get_circumference() { return 3.14 * radius; };
private:
double radius;
double circumference = 0;
point center;
}

C++ containers store elements of the same type, regardless of the type of the container - both vector and list behave the same way in this regard - they only hold elements of a specific type.
To overcome this restriction, you should use polymorphism - the type of the container's elements should be able to behave like Line or circle.
One way to do this is by using std::variant. Declare your container like this:
std::vector<std::variant<Line, circle>> my_list_of_shapes;
To add a shape to the list, use push_back:
Line my_line(...);
circle my_circle(...);
my_list_of_shapes.push_back(my_line);
my_list_of_shapes.push_back(my_circle);
To retrieve a shape from the list, access the list using a subscript (or an iterator), and use std::get to convert std::variant to your specific type:
circle your_circle = std::get<circle>(my_list_of_shapes[1]);
If you write some code which iterates through the container, and doesn't "know" what is stored at a specific place - Line or circle - you can use std::holds_alternative to check that:
for (auto shape: my_list_of_shapes)
{
if (std::holds_alternative<Line>(shape)
{
std::cout << std::get<Line>(shape).get_angle();
}
else if (std::holds_alternative<circle>(shape)
{
std::cout << std::get<circle>(shape).get_radius();
}
}

Related

Initializing a box with N particles arranged in a specific pattern

I'm new to C++, and as an exercise I'm trying to reproduce what was done by Metropolis et al. (Metropolis Monte Carlo).
What I have done thus far - Made 2 classes: Vector and Atom
class Vector {
public:
double x;
double y;
Vector() {
}
Vector (double x_, double y_) {
x = x_;
y = y_;
}
double len() {
return sqrt(x*x + y*y);
}
double lenSqr() {
return x*x + y*y;
}
};
class Atom {
public:
Vector pos;
Vector vel;
Vector force;
Atom (double x_, double y_) {
pos = Vector(x_, y_);
vel = Vector(0, 0);
force = Vector(0, 0);
}
double KE() {
return .5 * vel.lenSqr();
}
};
I am not certain that the way I have defined the class Atom is... the best way to go about things since I will not be using a random number generator to place the atoms in the box.
My problem:
I need to initialize a box of length L (in my case L=1) and load it with 224 atoms/particles in an offset lattice (I have included a picture). I have done some reading and I was wondering if maybe an array would be appropriate here.
One thing that I am confused about is how I could normalize the array to get the appropriate distance between the particles and what would happen to the array once the particles begin to move. I am also not sure how an array could give me the x and y position of each and every atom in the box.
Metropolis offset (hexagonal) lattice
Well, It seems, that generally you don't need to use array to represent the lattice. In practice most often it may sense to represent lattice as array only if your atoms can naturally move only on the cells (for example as figures in chess). But seems that your atoms can move in any direction (already not practicle to use such rigid structure as array, because it has naturally 4 or 8 directions for move in 2D) by any step (it is bad for arrays too, because in this case you need almost countless cells in array to represent minimal distance step).
So basically what do you need is just use array as storage for your 224 atoms and set particular position in lattice via pos parameter.
std::vector<Atom> atoms;
// initialize atoms to be in trigonal lattice
const double x_shift = 1. / 14;
const double y_shift = 1. / 16;
double x_offset = 0;
for (double y = 0; y < 1; y += y_shift){
for (double x = x_offset; x < 1; x += x_shift){
// create atom in position (x, y)
// and store it in array of atoms
atoms.push_back(Atom(x, y));
}
// every new row flip offset 0 -> 1/28 -> 0 -> 1/28...
if (x_offset == 0){
x_offset = x_shift / 2;
}
else{
x_offset = 0;
}
}
Afterwards you just need to process this array of atoms and change their positions, velocities and what you need else according to algorithm.

Vector of double to save distance of every sides in a polygon

everyone I want to do a function in a class Polygon who will be save the size of every sides of the polygon in a vector of double. My polygon is build thanks to the class Point. So I success to know how many point I have in my polygon and to print the drawing of the polygon to the screen. But the function to get the sides of every sides of the polygon thanks to the point, I still have not succeeded
This is my class Point :
Point::Point(double x, double y)
{
_x = x;
_y = y;
}
Point::Point(const Point& other)
{
_x = other._x;
_y = other._y;
}
double Point::getX() const
{
return _x;
}
double Point::getY() const
{
return _y;
}
double Point::distance(const Point& other)
{
return sqrt((getX() - other._x) * (getX() - other._x) + (getY() - other._y) *(getY() - other._y));
}
This is my header of class Polygon :
class Polygon
{
public:
Polygon();
~Polygon();
int numOfPoints() const;
vector<Point> getPoints() const;
vector<double> getSides() const;
protected:
std::vector<Point> _points;
};
and the cpp of Polygon :
Polygon::Polygon(){}
Polygon::~Polygon(){}
int Polygon::numOfPoints() const
{
return _points.size();
}
vector<Point> Polygon::getPoints() const
{
return _points;
}
vector<double> Polygon::getSides() const
{
vector<double> sides;
}
So I dont know how can I get the size of every sides thanks to class Point. I think it can be do thanks to the function distance of point, but I don't know how. If you can help me.
Thanks You !
First the small point: The following avoids double calculation of the differences (though compiler might optimise, it's better not to rely on it for doing so...).
double Point::distance(const Point& other)
{
double dx = _x - other._x;
double dy = _y - other._y;
return sqrt(dx * dx + dy * dy);
}
Then you have to iterate over all the points; you need at least two to have any distances at all, but two is the degenerate case (one distance only, all other numbers n result in n distances...):
vector<double> Polygon::getSides() const
{
vector<double> sides;
if(points.size() > 2)
{
sides.reserve(points.size());
std::vector<Point>::iterator end = points.end() - 1;
for(std::vector<Point>::iterator i = points.begin(); i != end; ++i)
sides.push_back(i->distance(*(i + 1)));
}
if(points.size() >= 2)
sides.push_back(points.front().distance(points.back()));
return sides;
}
Explanation:
if(points.size() > 2)
Only if we have more than two points, so triangle at least, we have true polyone. We now calculate the distances of this one, e. g. for a square ABCD the distances AB, BC, CD. Note that the distance DA is yet missing...
sides.reserve(points.size());
A polygon with n points has n sides. This prevents reallocation.
std::vector<Point>::iterator end = points.end() - 1;
end() points one past the end. Want to calculate distances i, i+1, so last element must be skipped.
for(std::vector<Point>::iterator i = points.begin(); i != end; ++i)
sides.push_back(i->distance(*(i + 1)));
Now calculating the distances...
if(points.size() >= 2)
sides.push_back(points.front().distance(points.back()));
This catches two cases: For true polygones this adds the last side closing it (in the example above: DA). Additionally, it handles the degenerate case of a single line (i = 2).
Actually, this could have been placed as well in front of the for loop. My variant calculates for points ABCD AB BC CD DA, the alternative DA, AB, BC, CD.
You might have noticed that we reserve only in the case of a true polygone. In the degenerate case, we are only inserting a single element, so it does not matter if we allocate the inner array before via reserve or at inserting the element...
Oh, and if you want to save a line of code:
for(std::vector<Point>::iterator i = points.begin() + 1; i != points.end(); ++i)
sides.push_back(i->distance(*(i - 1)));
Effectively the same, just reverted the points (calculating BA instead of AB).
You should iterate over the points in the polygon, calculating the distance to the previous point.
Something like the following should work (untested):
vector<double> Polygon::getSides() const {
vector<double> sides;
for(auto it = this->_points.begin(); it != this->_points.end(); it++) {
if(it == this->_points.begin())
sides.push_back(it->distance(*(this->_points.end() - 1)));
else
sides.push_back(it->distance(*(it - 1)));
}
return sides;
}
This starts at the first point and calculates the distance to the last point. For each point after that it calculates the distance to the previous point. Each time adding the distance to the output vector.
Note that I have assumed that the polygon is closed, i.e. the first point is connected to the last point. If the polygon contains no points, the return vector will be empty. If it contains only one point, it will contain a single element [0]. This results from calculating the distance from a point to the same point.
See this tutorial for more info on iterating over vectors: http://www.cprogramming.com/tutorial/stl/iterators.html

How can a find a face containing a predefined point when i have a planar graph embedded on a plane

I have a planar graph embedded on a plane (plane graph ) and want to search its faces.
The graph is not connected but consists of several connected graphs, which are not separately adressable (e.g. a subgraph can be contained in the face of another graph)
I want to find the polygons (faces) which include a certain 2d point.
The polygons are formed by the faces of the graphs. As the number of faces is quite big I would like to avoid to determine them beforehand.
What is the general complexity of such a search and what c++ library/ coding approach can I use to accomplish it.
Updated to clarify: I am refering to a graph in the xy plane here
You pose an interesting challenge. A relatively simple solution is possible if the polygon happens always to be convex, because in that case one need only ask whether the point of interest lies on the same flank (whether left or right) of all the polygon's sides. Though I know of no especially simple solution for the general case, the following code does seem to work for any, arbitrary polygon, as inspired indirectly by Cauchy's famous integral formula.
One need not be familiar with Cauchy to follow the code, for comments within the code explain the technique.
#include <vector>
#include <cstddef>
#include <cstdlib>
#include <cmath>
#include <iostream>
// This program takes its data from the standard input
// stream like this:
//
// 1.2 0.5
// -0.1 -0.2
// 2.7 -0.3
// 2.5 2.9
// 0.1 2.8
//
// Given such input, the program answers whether the
// point (1.2, 0.5) does not lie within the polygon
// whose vertices, in sequence, are (-0.1, -0.2),
// (2.7, -0.3), (2.5, 2.9) and (0.1, 2.8). Naturally,
// the program wants at least three vertices, so it
// requires the input of at least eight numbers (where
// the example has four vertices and thus ten numbers).
//
// This code lacks really robust error handling, which
// could however be added without too much trouble.
// Also, its function angle_swept() could be shortened
// at cost to readability; but this is not done here,
// since the function is already hard enough to grasp as
// it stands.
//
//
const double TWOPI = 8.0 * atan2(1.0, 1.0); // two times pi, or 360 deg
namespace {
struct Point {
double x;
double y;
Point(const double x0 = 0.0, const double y0 = 0.0)
: x(x0), y(y0) {}
};
// As it happens, for the present code's purpose,
// a Point and a Vector want exactly the same
// members and operations; thus, make the one a
// synonym for the other.
typedef Point Vector;
std::istream &operator>>(std::istream &ist, Point &point) {
double x1, y1;
if(ist >> x1 >> y1) point = Point(x1, y1);
return ist;
}
// Calculate the vector from one point to another.
Vector operator-(const Point &point2, const Point &point1) {
return Vector(point2.x - point1.x, point2.y - point1.y);
}
// Calculate the dot product of two Vectors.
// Overload the "*" operator for this purpose.
double operator*(const Vector &vector1, const Vector &vector2) {
return vector1.x*vector2.x + vector1.y*vector2.y;
}
// Calculate the (two-dimensional) cross product of two Vectors.
// Overload the "%" operator for this purpose.
double operator%(const Vector &vector1, const Vector &vector2) {
return vector1.x*vector2.y - vector1.y*vector2.x;
}
// Calculate a Vector's magnitude or length.
double abs(const Vector &vector) {
return std::sqrt(vector.x*vector.x + vector.y*vector.y);
}
// Normalize a vector to unit length.
Vector unit(const Vector &vector) {
const double abs1 = abs(vector);
return Vector(vector.x/abs1, vector.y/abs1);
}
// Imagine standing in the plane at the point of
// interest, facing toward a vertex. Then imagine
// turning to face the next vertex without leaving
// the point. Answer this question: through what
// angle did you just turn, measured in radians?
double angle_swept(
const Point &point, const Point &vertex1, const Point &vertex2
) {
const Vector unit1 = unit(vertex1 - point);
const Vector unit2 = unit(vertex2 - point);
const double dot_product = unit1 * unit2;
const double cross_product = unit1 % unit2;
// (Here we must be careful. Either the dot
// product or the cross product could in theory
// be used to extract the angle but, in
// practice, either the one or the other may be
// numerically problematical. Use whichever
// delivers the better accuracy.)
return (fabs(dot_product) <= fabs(cross_product)) ? (
(cross_product >= 0.0) ? (
// The angle lies between 45 and 135 degrees.
acos(dot_product)
) : (
// The angle lies between -45 and -135 degrees.
-acos(dot_product)
)
) : (
(dot_product >= 0.0) ? (
// The angle lies between -45 and 45 degrees.
asin(cross_product)
) : (
// The angle lies between 135 and 180 degrees
// or between -135 and -180 degrees.
((cross_product >= 0.0) ? TWOPI/2.0 : -TWOPI/2.0)
- asin(cross_product)
)
);
}
}
int main(const int, char **const argv) {
// Read the x and y coordinates of the point of
// interest, followed by the x and y coordinates of
// each vertex in sequence, from std. input.
// Observe that whether the sequence of vertices
// runs clockwise or counterclockwise does
// not matter.
Point point;
std::vector<Point> vertex;
std::cin >> point;
{
Point point1;
while (std::cin >> point1) vertex.push_back(point1);
}
if (vertex.size() < 3) {
std::cerr << argv[0]
<< ": a polygon wants at least three vertices\n";
std::exit(1);
}
// Standing as it were at the point of interest,
// turn to face each vertex in sequence. Keep
// track of the total angle through which you
// have turned.
double cumulative_angle_swept = 0.0;
for (size_t i = 0; i < vertex.size(); ++i) {
// In an N-sided polygon, vertex N is again
// vertex 0. Since j==N is out of range,
// if i==N-1, then let j=0. Otherwise,
// let j=i+1.
const size_t j = (i+1) % vertex.size();
cumulative_angle_swept +=
angle_swept(point, vertex[i], vertex[j]);
}
// Judge the point of interest to lie within the
// polygon if you have turned a complete circuit.
const bool does_the_point_lie_within_the_polygon =
fabs(cumulative_angle_swept) >= TWOPI/2.0;
// Output.
std::cout
<< "The angle swept by the polygon's vertices about the point\n"
<< "of interest is " << cumulative_angle_swept << " radians ("
<< ((360.0/TWOPI)*cumulative_angle_swept) << " degrees).\n"
<< "Therefore, the point lies "
<< (
does_the_point_lie_within_the_polygon
? "within" : "outside of"
)
<< " the polygon.\n";
return !does_the_point_lie_within_the_polygon;
}
Of course, the above code is just something I wrote, because your challenge was interesting and I wanted to see if I could meet it. If your application is important, then you should both test and review the code, and please revise back here any bugs you find. I have tested the code against two or three cases, and it seems to work, but for important duty it would want more exhaustive testing.
Good luck with your application.

C++ Data Structure for storing 3 dimensions of floats

I've implemented a 3D strange attractor explorer which gives float XYZ outputs in the range 0-100, I now want to implement a colouring function for it based upon the displacement between two successive outputs.
I'm not sure of the data structure to use to store the colour values for each point, using a 3D array I'm limited to rounding to the nearest int which gives a very coarse colour scheme.
I'm vaguely aware of octtrees, are they suitable in this siutation?
EDIT: A little more explanation:
to generate the points i'm repeatedly running this:
(a,b,c,d are random floats in the range -3 to 3)
x = x2;
y = y2;
z = z2;
x2 = sin(a * y) - z * cos(b * x);
y2 = z2 * sin(c * x) - cos(d * y);
z2 = sin(x);
parr[i][0]=x;
parr[i][1]=y;
parr[i][2]=z;
which generates new positions for each axis each run, to colour the render I need to take the distance between two successive results, if I just do this with a distance calculation between each run then the colours fade back and forth in equilibrium so I need to take running average for each point and store it, using a 3dimenrsionl array is too coarse a colouring and I'm looking for advice on how to store the values at much smaller increments.
Maybe you could drop the 2-dim array off and use an 1-dim array of
struct ColoredPoint {
int x;
int y;
int z;
float color;
};
so that the code would look like
...
parr[i].x = x;
parr[i].y = y;
parr[i].z = z;
parr[i].color = some_computed_color;
(you may also wish to encapsulate the fields and use class ColoredPoint with access methods)
I'd probably think bout some kind of 3-d binary search tree.
template <class KEY, class VALUE>
class BinaryTree
{
// some implementation, probably available in libraries
public:
VALUE* Find(const KEY& key) const
{
// real implementation is needed here
return NULL;
}
};
// this tree nodes wil actually hold color
class BinaryTree1 : public BinaryTree<double, int>
{
};
class BinaryTree2 : public BinaryTree<double, BinaryTree1>
{
};
class BinaryTree3 : public BinaryTree<double, BinaryTree2>
{
};
And you function to retreive the color from this tree would look like that
bool GetColor(const BinaryTree3& tree, double dX, double dY, double& dZ, int& color)
{
BinaryTree2* pYTree = tree.Find(dX);
if( NULL == pYTree )
return false;
BinaryTree1* pZTree = pYTree->Find(dY);
if( NULL == pZTree )
return false;
int* pCol = pZTree->Find(dZ);
if( NULL == pCol )
return false;
color = *pCol;
return true;
}
Af course you will need to write the function that would add color to this tree, provided 3 coordinates X, Y and Z.
std::map appears to be a good candidate for base class.

How do I delete the closest "Point" object in a STD::List to some x,y?

I have a point class like:
class Point {
public:
int x, y;
Point(int x1, int y1)
{
x = x1;
y = y1;
}
};
and a list of points:
std::list <Point> pointList;
std::list <Point>::iterator iter;
I'm pushing points on to my pointList (although the list might contain no Points yet if none have been pushed yet).
I have two questions:
How can I delete the closest point to some arbitrary (x, y) from the list?
Lets say I have the x,y (5,12) and I want to find the Point in the list closest to that point and remove it from the STD::List.
I know I'll have to use the distance formula and I'll have to iterate through the list using an iterator but I'm having some trouble conceptualizing how I'll keep track of which point is the closest as I iterate through the list.
How can I return an array or list of points within x radius of a given (x,y)?
Similar to the last question except I need a list of pointers to the "Point" objects within say 5 radius of a given (x,y). Also, should I return an array or a List?
If anyone can help me out, I'm still struggling my way through C++ and I appreciate it.
Use a std::list::iterator variable to keep track of the closest point as you loop through the list. When you get to the end of the list it will contain the closest point and can be used to erase the item.
void erase_closest_point(const list<Point>& pointList, const Point& point)
{
if (!pointList.empty())
{
list<Point>::iterator closestPoint = pointList.begin();
float closestDistance = sqrt(pow(point.x - closestPoint->x, 2) +
pow(point.y - closestPoint->y, 2));
// for each point in the list
for (list<Point>::iterator it = closestPoint + 1;
it != pointList.end(); ++it)
{
const float distance = sqrt(pow(point.x - it->x, 2) +
pow(point.y - it->y, 2));
// is the point closer than the previous best?
if (distance < closestDistance)
{
// replace it as the new best
closestPoint = it;
closestDistance = distance
}
}
pointList.erase(closestPoint);
}
}
Building a list of points within a radius of a given point is similar. Note that an empty radius list is passed into the function by reference. Adding the points to the list by reference will eliminate the need for copying all of the points when returning the vector by value.
void find_points_within_radius(vector<Point>& radiusListOutput,
const list<Point>& pointList,
const Point& center, float radius)
{
// for each point in the list
for (list<Point>::iterator it = pointList.begin();
it != pointList.end(); ++it)
{
const float distance = sqrt(pow(center.x - it->x, 2) +
pow(center.y - it->y, 2));
// if the distance from the point is within the radius
if (distance > radius)
{
// add the point to the new list
radiusListOutput.push_back(*it);
}
}
}
Again using copy if:
struct RadiusChecker {
RadiusChecker(const Point& center, float radius)
: center_(center), radius_(radius) {}
bool operator()(const Point& p)
{
const float distance = sqrt(pow(center_.x - p.x, 2) +
pow(center_.y - p.y, 2));
return distance < radius_;
}
private:
const Point& center_;
float radius_;
};
void find_points_within_radius(vector<Point>& radiusListOutput,
const list<Point>& pointList,
const Point& center, float radius)
{
radiusListOutput.reserve(pointList.size());
remove_copy_if(pointList.begin(), pointList.end(),
radiusListOutput.begin(),
RadiusChecker(center, radius));
}
Note that the sqrt can be removed if you need extra performance since the square of the magnitude works just as well for these comparisons. Also, if you really want to increase performance than consider a data structure that allows for scene partitioning like a quadtree. The first problem is closely related to collision detection and there is a ton of valuable information about that topic available.
You are right on how it should be made. Just iterate through all items in the list and keep track of the smallest distance already found, and the nearest point you found in two variables, making sure you don't match the point with itself if the problem states so. Then just delete the point you found.
How this is exactly made is kept as an exercise.
If you want to get a list of points in a given radius from another point, iterate the list and build a second list containing only the points within the specified range.
Again, how it's made in code is left to you as an exercise.
You can do this using a combination of the STL and Boost.Iterators and Boost.Bind -- I'm pasting the whole source of the solution to your problem here for your convenience:
#include <list>
#include <cmath>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/bind.hpp>
#include <cassert>
using namespace std;
using namespace boost;
struct Point {
int x, y;
Point() : x(0), y(0) {}
Point(int x1, int y1) : x(x1), y(y1) {}
Point(Point const & other) : x(other.x), y(other.y) {}
Point & operator=(Point rhs) { rhs.swap(*this); return *this; }
void swap(Point & other) { std::swap(other.x, x); std::swap(other.y, y); }
};
double point_distance(Point const & first, Point const & second) {
double x1 = first.x;
double x2 = second.x;
double y1 = first.y;
double y2 = second.y;
return sqrt( ((x2 - x1) * (x2 -x1)) + ((y2 - y1) * (y2 - y1)) );
}
int main(int argc, char * argv[]) {
list<Point> points;
points.push_back(Point(1, 1));
points.push_back(Point(2, 2));
points.push_back(Point(3, 3));
Point source(0, 0);
list<Point>::const_iterator closest =
min_element(
make_transform_iterator(
points.begin(),
bind(point_distance, source, _1)
),
make_transform_iterator(
points.end(),
bind(point_distance, source, _1)
)
).base();
assert(closest == points.begin());
return 0;
}
The meat of the solution is to transform each element in the list using the transform iterator using the point_distance function and then get the minimum distance from all the distances. You can do this while traversing the list, and in the end reach into the transform_iterator to get the base iterator (using the base() member function).
Now that you have that iterator, you can replace the assert(closest == points.begin()) with points.erase(closest).
I agree with the previous solution, and just wanted to add another thought. Although your Point class isn't very large and so a copy isn't really a problem, you might consider using Point* for your list. This way, when you create your second list, you would store the pointer to the same class. The down-side of this would be if you were deleting from multiple lists without a "master" that manages all created points, you could either create a memory leak if you didn't delete the underlying class or accidentally delete a class that was still being used in another list. Something to consider, though, depending on how your system evolves.
You have to keep the iterator to delete it afterwards.
std::list<Point>::iterator closest;
std::list<Point>::iterator it = pointList.begin();
double min_dist=dist(your_point, *it);
++it;
for (; it != pointList.end(); ++it)
{
double actual_dist = dist(your_point, *it);
if (actual_dist < min_dist)
{
min_dist = actual_dist;
closest = it;
}
}
pointList.erase(closest);