Creating boost.geometry.model.polygon from 2D C List - c++

Supposed I have the following dataset
double * data = (double *) malloc(sizeof(double) * 100 * 2);
for (ii = 0; ii < 100; ii++) {
data[2*ii] = ii;
data[2*ii + 1] = ii;
}
how can I create a boost polygon from this data?
thanks

A complete example
#include <iostream>
#include <boost/polygon/polygon.hpp>
#include <vector>
// Some typedefs
namespace bpl = boost::polygon;
typedef bpl::polygon_data<double> Polygon;
typedef bpl::polygon_traits<Polygon>::point_type Point;
int main() {
// Your C-style data (assumed (x,y) pairs)
double * data = (double *) malloc(sizeof(double) * 100 * 2);
for (int ii = 0; ii < 100; ii++) {
data[2*ii] = ii;
data[2*ii + 1] = ii;
}
// Convert to points
std::vector<Point> points;
for (int i=0;i<100;++i)
points.push_back(Point(data[2*i],data[2*i+1]));
// Create a polygon
Polygon polygon;
polygon.set(points.begin(),points.end());
// Do something with the polygon
std::cout << "Perimeter : " << bpl::perimeter(polygon) << std::endl;
std::cout << "Area : " << bpl::area(polygon) << std::endl;
return 0;
}
Just to illustrate the flexibility you actually have: with a bit of extra typedef work, its possible to define your own pair-of-doubles point type which can be aliased onto your data, which avoids the intermediate copy...
#include <iostream>
#include <boost/polygon/polygon.hpp>
#include <vector>
// Define a point type which can be aliased to your 'C' points
struct Pt {
double x;
double y;
};
// Some typedefs
namespace bpl = boost::polygon;
typedef bpl::polygon_data<double> Polygon;
// Add the necessary to use Pt
namespace boost {
namespace polygon {
template <> struct geometry_concept<Pt> {typedef point_concept type;};
template <> struct point_traits<Pt> {
typedef double coordinate_type;
static inline coordinate_type get(const Pt& pt,orientation_2d orient) {
return (orient == HORIZONTAL ? pt.x : pt.y);
}
};
template <> struct point_mutable_traits<Pt> {
static inline void set(Pt& pt, orientation_2d orient, int value) {
if(orient == HORIZONTAL)
pt.x = value;
else
pt.y = value;
}
static inline Pt construct(double x,double y) {
Pt r;
r.x=x;
r.y=y;
return r;
}
};
}
}
int main() {
// Your C-style data (assumed (x,y) pairs)
double * data = (double *) malloc(sizeof(double) * 100 * 2);
for (int ii = 0; ii < 100; ii++) {
data[2*ii] = ii;
data[2*ii + 1] = ii;
}
// Reinterpret your data as an array of Pt
const Pt*const pts=reinterpret_cast<const Pt*>(data);
// Create a polygon
Polygon polygon;
polygon.set(pts,pts+100);
// Do something with the polygon
std::cout << "Perimeter : " << bpl::perimeter(polygon) << std::endl;
std::cout << "Area : " << bpl::area(polygon) << std::endl;
return 0;
}
And this trend could be continued to a custom polygon class.

Related

Run-Time Check Failure #2 - Stack around the variable 'c2d' was corrupted. with c++

I'm studying for an exam and this is on my practice test. The question is "Which type of error does the following code fragment cause?"
Why is there an error?
struct C2D {
double x, y;
};
class Polygon {
int point;
C2D arr[];
public:
Polygon(int point_, C2D arr_[]) {
point = point_;
memcpy(arr, arr_, sizeof(C2D) * point);
};
void print() const {
for (int i = 0; i < point; i++) {
cout << arr[i].x << " " << arr[i].y << endl;
}
};
};
int main() {
C2D c2d[3];
c2d[0].x = 1;
c2d[0].y = 2;
c2d[1].x = 3;
c2d[1].y = 4;
c2d[2].x = 5;
c2d[2].y = 6;
Polygon p1(3, c2d);
p1.print();
return 0;
}
You didn't specify number of elements for the member
C2D arr[];
so there are no memory allocated for that.
You should use std::vector to allocate elements dynamically.
#include <iostream>
#include <vector>
#include <cstring>
using std::cout;
using std::endl;
struct C2D {
double x, y;
};
class Polygon {
int point;
std::vector<C2D> arr;
public:
Polygon(int point_, C2D arr_[]) : arr(point_) { // allocate point_ elements for arr
point = point_;
memcpy(arr.data(), arr_, sizeof(C2D) * point); // copy data using data()
};
void print() const {
for (int i = 0; i < point; i++) {
cout << arr[i].x << " " << arr[i].y << endl;
}
};
};
int main() {
C2D c2d[3];
c2d[0].x = 1;
c2d[0].y = 2;
c2d[1].x = 3;
c2d[1].y = 4;
c2d[2].x = 5;
c2d[2].y = 6;
Polygon p1(3, c2d);
p1.print();
return 0;
}

Error with global vector of object pointers c++

I am developing a 2D physics engine in c++, and one of the main structures I am using is name RigidBody. In order to easily iterate through all of the RigidBody objects in each time step, I attempted to create a global vector of RigidBody object pointers.
vector<RigidBody*> RigidBodies
As suggested in other StackOverflow answers, I declared the global variable in a header file, and defined it in one of the other project .cpp files. However, when I attempt to access member functions or variables, I get bogus values. Below are my source and header files. Could someone please let me know if there is an error with this or if I am doing something fundamentally wrong, as I have been trying to find an error for a few days, and have not been able to figure it out yet.
main.cpp:
#include <iostream>
#include <vector>
#include "polygon.h"
#include "rendering.h"
int test;
std::vector<RigidBody*> RigidBodies;
RigidBody * rigPtr;
void CreateBody() {
Material m1; // Settings for ROCK.
m1.density = 0.6;
m1.restitution = 0.1;
float volume = 1;
Vector p0 = {0,1};
Vector p1 = {1,1};
Vector p2 = {1,0};
Vector p3 = {0,0};
std::vector<Vector*> Points;
Points.push_back(&p0);
Points.push_back(&p1);
Points.push_back(&p2);
Points.push_back(&p3);
//std::cout << Points.at(0)->y << '\n';
Polygon pol1(Points, m1, volume);
Polygon * polPtr = &pol1;
//std::cout << pol1.Points.at(0)->y << '\n';
std::cout << "polygon created" << '\n';
Vector pos1;
pos1.x = 10;
pos1.y = 10;
RigidBody r1(pos1, polPtr);
rigPtr = &r1;
std::cout << "rigid body created" << '\n';
// std::cout << RigidBodies.at(0)->dt << '\n';
}
// MAIN
int main() {
test = 3;
//std::cout << test << '\n';
test = 6;
CreateBody();
RigidBodies.push_back(rigPtr);
//std::cout << test << '\n';
unsigned int lastTime = SDL_GetTicks();
unsigned int currentTime;
SDL_Renderer* renderer = InitializeRender();
while(1) {
currentTime = SDL_GetTicks();
if (currentTime - lastTime > 33) {
//RigidBodies.at(0)->Step();
Render(renderer, RigidBodies);
lastTime = SDL_GetTicks();
}
}
return(0);
}
rendering.cpp:
#include <iostream>
#include "polygon.h"
#include "rendering.h"
SDL_Renderer* InitializeRender() {
SDL_Window * window = NULL;
window = SDL_CreateWindow
(
"RIGID BODIES SIM", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
SDL_WINDOW_SHOWN
);
// Setup renderer
SDL_Renderer * renderer = NULL;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
return(renderer);
}
void Render(SDL_Renderer * renderer, std::vector<RigidBody*> RigidBodies) {
float scale = 10; // METERS to PIXELS.
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); // Clear screen.
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); // Set polygon drawing color (GREEN)
std::cout << RigidBodies.at(0)->dt << '\n';
for (int j = 0; j < RigidBodies.size(); j++) {
RigidBody * rPtr = RigidBodies.at(j); // Not recognizing rigid body pointer correctly
//std::cout << rPtr->dt << '\n';
Polygon * polyPtr = rPtr->p;
std::cout << "hey1" << '\n';
int size = polyPtr->Points.size(); // ERROR HERE //
std::cout << "hey2" << '\n';
// std::cout << polyPtr->Points.at(0)->y << '\n';
for (int i = 0; i < size; i++) {
std::cout << "hey3" << '\n';
auto pointPtr1 = polyPtr->Points.at(i);
int lastIndex = size - 1;
//std::cout << i+1 << '\n';
auto pointPtr2 = polyPtr->Points.at((i + 1) % (lastIndex)); // Modulo so last point links back up to first one.
SDL_RenderDrawLine(renderer, (rPtr->position.x + pointPtr1->x) * scale, SCREEN_HEIGHT
- (rPtr->position.y + pointPtr1->y) * scale, (rPtr->position.x + pointPtr2->x) * scale,
SCREEN_WIDTH - (rPtr->position.y + pointPtr2->y * scale));
}
}
SDL_RenderPresent(renderer);
}
rendering.h:
#include <vector>
#include <SDL2/SDL.h>
#ifndef RENDERING_H
#define RENDERING_H
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
//SDL_Renderer * renderer;
SDL_Renderer* InitializeRender();
void Render(SDL_Renderer*, std::vector<RigidBody*>);
#endif
rigid_bodies.cpp
// Joaquin Matias Giorgi jmgiorgi#bu.edu Impulse-Based Physics Engine 2D //
#include <iostream>
#include <math.h>
#include <SDL2/SDL.h>
#include <vector>
#include "polygon.h"
using namespace std;
vector<RigidBody*> RigidBodies;
// VECTOR STUFF //
// Multiplication by scalar quantity.
Vector Vector::operator*(const float scalar) {
Vector vout;
vout.x = this->x * scalar;
vout.y = this->y * scalar;
return(vout);
}
// Addition overload.
Vector Vector::operator+=(const Vector vec) {
Vector vout;
vout.x = this->x + vec.x;
vout.y = this->y + vec.y;
return(vout);
}
float dot (Vector vec1, Vector vec2) {
float out = (vec1.x * vec2.x) + (vec1.y * vec2.y);
return(out);
}
float cross2d (Vector vec1, Vector vec2) {
// magnitude of perpendicular vector in 3d case.
float out = (vec1.x * vec2.y) - (vec1.y * vec2.x);
return(out);
}
// POLYGON Struct Methods //
Polygon::Polygon(vector< Vector* > Points1, Material m1, float volume1) {
Points = Points1;
m = m1;
volume = volume1;
}
float Polygon::ComputeMass() {
float mass = m.density * this->volume;
return(mass);
}
// RIGID BODY Struct Methods //
RigidBody::RigidBody(Vector position1, Polygon * p1) {
std::cout << test << '\n';
position = position1;
p = p1;
mass = p1->ComputeMass();
orientation = 0;
angularVelocity = 0;
dt = .033;
gravity.x = 0;
gravity.y = -9.8;
velocity.x = 0;
velocity.y = 0;
//RigidBodies.push_back(this); // Push to global vector of all RigidBodies.
}
// UPDATE at each iteration.
void RigidBody::Step() {
this->velocity += this->gravity * this->dt;
this->position += this->velocity * this->dt;
this->orientation += this->angularVelocity * this->dt;
}
polygon.h:
#include <vector>
#ifndef POLYGON_H
#define POLYGON_H
struct Vector {
float x;
float y;
// Multiplication by scalar quantity.
Vector operator*(const float);
// Addition overload.
Vector operator+=(const Vector);
};
struct Material {
float density;
float restitution;
};
struct Polygon {
std::vector< Vector* > Points;
float volume;
Material m;
Polygon(std::vector< Vector* >, Material, float);
float ComputeMass();
};
struct RigidBody {
float mass;
float volume;
float dt;
// Linear
Vector position;
Vector gravity;
Vector velocity;
float acceleration;
// Angular
float orientation;
float angularVelocity;
float torque;
Polygon * p;
// Constructor
RigidBody(Vector, Polygon*);
// UPDATE at each iteration.
void Step();
};
// DECLARATION
extern std::vector<RigidBody*> RigidBodies; // Global Vector of RigidBody Pointers.
#endif
Makefile:
sim:
g++ -std=c++11 main.cpp rigid_bodies.cpp rendering.cpp -I include -L lib -l SDL2-2.0.0
In your function CreateBody, RigidBody r1 is created on the stack and ceases to exist when the function returns. Your pointer rigPtr (and the pointers in Points and polPtr) is no longer valid after the end of the function. If you call the CreateBody in a loop you will probably see that you get the same pointers for every call.
The simplest solution is to not use pointers at all, your objects are fairly small and shouldn't be too expensive to copy (or even cheaper to move).
If you really want to use pointers you need to allocate your objects on the heap rather than the stack using new. Note that these objects will then need to the deallocated using delete. A safer solution would be to wrap your pointers in std::shared_ptr or std::unique_ptr which takes care of deleting the objects automatically.

Creating multiple instances of c++ library

I am trying to create multiple instances of a static c++ library I wrote, but I can't create multiple instances of it... When I create two instances and write different data to them, I read the same data from both of the instances. Here is my code:
.cpp file:
// MathFuncsLib.cpp
// compile with: cl /c /EHsc MathFuncsLib.cpp
// post-build command: lib MathFuncsLib.obj
/*
DECLARING VECTORS
|3,6,4|
|9,1,5|
|2,0,2|
|5,3,6|
Should be inputted as:
int a[] = {3,6,4,9,1,5,2,0,2,5,3,6} with x = 3 and y = 4
Inputting training vals:
|0.1 (inp1),0.1 (inp2) ,0.1 (targeted output)| depends on the number of inputs and outputs
|9,1,5|
|2,0,2|
|5,3,6|
*/
//#include "stdafx.h"
#include "vector.h"
#include "iostream"
#define DEBUG
#include <stdexcept>
//using namespace std;
double* vectorLib::arrayPtr;
int vectorLib::x;
int vectorLib::y;
vectorLib::vectorLib(int xInp, int yInp) {
vectorLib::arrayPtr = new double[xInp*yInp];
vectorLib::x = xInp;
vectorLib::y = yInp;
//return 0;
}
double vectorLib::sigmoid(double inp) {
return 1 / (1 + exp(-inp));
}
double* vectorLib::getArrayPtr() {
return vectorLib::arrayPtr;
}
double vectorLib::read(int xInp, int yInp) {
#ifdef DEBUG
if (xInp >= vectorLib::x) {
std::cout << "X_OUT_OF_BOUNDS_VECTOR_READ\n";
while (1);
}
if (yInp >= vectorLib::y) {
std::cout << "X_OUT_OF_BOUNDS_VECTOR_READ\n";
while (1);
}
#endif // DEBUG
return *(arrayPtr + xInp + vectorLib::x*yInp);
}
void vectorLib::write(int xInp, int yInp, double data) {
#ifdef DEBUG
if (xInp >= vectorLib::x) {
std::cout << "X_OUT_OF_BOUNDS_VECTOR_WRITE\n";
while (1);
}
if (yInp >= vectorLib::y) {
std::cout << "X_OUT_OF_BOUNDS_VECTOR_WRITE\n";
while (1);
}
#endif // DEBUG
vectorLib::arrayPtr[xInp + vectorLib::x*yInp] = data;
}
void vectorLib::writeArr(double* inpArr) {
int i;
for (i = 0; i < vectorLib::x*vectorLib::y; i++) {
vectorLib::arrayPtr[i] = *(inpArr + i);
}
}
void vectorLib::sigmoidVect() {
int yy;
int xx;
for (yy = 0; yy < vectorLib::y; yy++) {
for (xx = 0; xx < vectorLib::x; xx++) {
write(xx, yy, sigmoid(read(xx, yy)));
}
}
write(0, vectorLib::y - 1, 1);
}
int vectorLib::getX() {
return vectorLib::x;
}
int vectorLib::getY() {
return vectorLib::y;
}
int vectorLib::totalVectSize() {
return vectorLib::x * vectorLib::y;
}
void vectorLib::printVector() {
int yy;
int xx;
for (yy = 0; yy < y; yy++) {
for (xx = 0; xx < x; xx++) {
std::cout << vectorLib::read(xx, yy);
if (xx + 1 != x) {
std::cout << ",";
}
}
std::cout << "\n";
}
}
vectorLib* vectorLib::vectorMult(vectorLib* vect1, vectorLib* vect2) {
#ifdef DEBUG
if (vect1->getX() != vect2->getY()) {
std::cout << "INPUTS_DONT_MATCH_VECTORMULT\n";
while (1);
}
#endif // DEBUG
vectorLib toRet(vect1->getX(), vect2->getY());
int i;
for (i = 0; i < vect2->getX(); i++) {
int p;
for (p = 0; p < vect1->getY(); p++) {
double tempOut = 0;
int q;
for (q = 0; q < vect1->getX(); q++)
{
tempOut += vect1->read(q, p) * vect2->read(i, q);
}
toRet.write(i, p, tempOut);
}
}
return &toRet;
}
.h file:
//#include "stdafx.h"
using namespace std;
class vectorLib
{
//int x, y;
public:
static double* arrayPtr;
static int x;
static int y;
//Constructor takes x and y of the vector
vectorLib(int xInp, int yInp);
//The pointer to the array that holds all the doubles in the vector
static double* getArrayPtr();
//Read the vector at a specified x and y
static double read(int xInp, int yInp);
//Write one double to a specific location
static void write(int xInp, int yInp, double data);
//Write the array inside the vector class
static void writeArr(double* inpArr);
//Takes sigmoid of whole vector
static void sigmoidVect();
//Returns x of vector
static int getX();
//Returns y of vector
static int getY();
//Returns total size of vector
static int totalVectSize();
//Returns a vector pointer to the multiplication result
static vectorLib* vectorMult(vectorLib* vect1, vectorLib* vect2);
//Prints vector
static void printVector();
private:
static double sigmoid(double inp);
};
Main file:
#define DEBUG
#include "stdafx.h"
#include "vector.h"
#include "iostream"
using namespace std;
int main()
{
vectorLib testVectLol(1, 3);
vectorLib testVect(3, 4);
double vectInp[] = { 1,1,1,
1,1,1,
1,1,1,
1,1,1};
double vectInp2[] = { 0.5,0.5,0.5 };
testVect.writeArr(vectInp);
testVectLol.writeArr(vectInp2);
testVect.printVector();// Both print 0.5, 0.5, 0,5
testVectLol.printVector();// Both print 0.5, 0.5, 0,5
while (1);
return 0;
}
Thanks in advance! I've been struggling with this for hours. I would really appreciate any help!
Jasper

CGAL + Find edge length using EdgeIterator

I am new to CGAL and am trying to find the length of each each edge in a mesh. I don't see any or length member functions or any way of easily getting the points on either side of the edge.
Here is where I have gotten so far. How do I get either the points on either end of the edge or the size of the edge itself?
#include <iostream>
#include <string>
#include <CGAL/Cartesian.h>
#include <CGAL/Filtered_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
typedef double Real;
typedef CGAL::Cartesian<Real> Kernel0;
// Use a filtered kernel so that all predicates are exact.
typedef CGAL::Filtered_kernel<Kernel0> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Kernel::Point_3 Point;
void Edge_Analysis(Polyhedron mesh){
float mean = 0, min, max, length;
int count = 0; bool init = true;
for (Polyhedron::Edge_const_iterator edgeIter = mesh.edges_begin(); edgeIter != mesh.edges_end(); ++edgeIter){
Point a = edgeIter.prev()->vertex()->point();
Point b = edgeIter.vertex()->point();
length = CGAL::sqrt(CGAL::squared_distance(a, b));
++count;
if (init){
mean = min = max = length;
init = false;
}
else{
if (length < min) min = length;
if (length > max) max = length;
}
mean += length;
}
mean /= count;
std::cout << min << " " << max << " " << mean << "\n";
}
int main(int argc, char **argv){
Polyhedron mesh;
// Read the input mesh from standard input in OFF format.
if (!(std::cin >> mesh)) {
std::cerr << "Cannot read input mesh\n";
return 1;
}
Edge_Analysis(mesh);
return 0;
}
The only mistake that should be fixed in order to compile is:
const Point& a = edgeIter->prev()->vertex()->point();
const Point& b = edgeIter->vertex()->point();
You should use CGAL::Exact_predicates_inexact_constructions_kernel instead of Kernel. You should take a const ref on mesh if you want to avoid an unneeded copy.

Have shape and circle class, and point class. Segmentation fault when creating circle with point class as one parameter

Here is my Shape.h. Ignore all the code that is commented out. That is from a version that I believe was incorrect but I left it in there in case I was wrong.
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include "Point.h"
using namespace std;
class Shape {
public:
Shape() {}
virtual ~Shape() {}
/*
virtual float calcArea(const Shape& s) const = 0;
virtual float calcCircum(const Shape& s) const = 0;
virtual string calcBox(const Shape& s) const = 0;
virtual void display(const Shape& s) const = 0;
*/
virtual float calcArea() const = 0;
virtual float calcCircum() const = 0;
virtual string calcBox() const = 0;
virtual void display() const = 0;
};
class Circle : public Shape {
public:
int radius;
int pointX;
int pointY;
Point *middlePoint;
float PI;
Circle() : Shape() {
middlePoint = new Point(0,0);
radius = 0;
}
~Circle() {}
Circle(int rad, Point& p) : Shape() {
PI = 3.141592;
*middlePoint = p;
pointX = p.getX();
pointY = p.getY();
radius = rad;
}
// float calcArea(const Circle& s) const {
float calcArea() const {
float tempArea;
// tempArea = PI * s.radius * s.radius;
tempArea = PI * radius * radius;
return tempArea;
}
// float calcCircum(const Circle& s) const {
float calcCircum() const {
// int diameter = 2 * s.radius;
int diameter = 2 * radius;
float tempCircum;
tempCircum = PI * diameter;
return tempCircum;
}
// string calcBox(const Circle& s) const {
string calcBox() const {
// int x = s.pointX;
// int y = s.pointY;
// int r = s.radius;
int x = pointX;
int y = pointY;
int r = radius;
int tlX = x - r;
int tlY = y + r;
int blX = x - r;
int blY = y - r;
int trX = x + r;
int trY = y + r;
int brX = x + r;
int brY = y - r;
Point *topLeft = new Point(tlX,tlY);
Point *bottomLeft = new Point(blX,blY);
Point *topRight = new Point(trX,trY);
Point *bottomRight = new Point(brX,brY);
stringstream output;
string tempOut;
output << *topLeft << *bottomLeft << *topRight << *bottomRight;
tempOut = output.str();
return tempOut;
}
// void display(const Circle& s) const {
void display() const {
cout << "Class Name: Circle" << endl;
// float tmpArea = calcArea(s);
float tmpArea = calcArea();
cout << "Area = " << tmpArea << endl;
// cout << "Radius = " << s.radius << endl;
cout << "Radius = " << radius << endl;
// float tmpCircum = calcCircum(s);
float tmpCircum = calcCircum();
cout << "Circumference = " << tmpCircum << endl;
cout <<"Middle Point = " << middlePoint;
// string bbox = calcBox(s);
string bbox = calcBox();
cout <<"Bounding Box Points = " << bbox;
}
};
Here is my TMA4Question1.cpp code.
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include "Shape.h"
int main() {
Point *circlePoint = new Point(10,-5);
Circle *mainCircle = new Circle(23,*circlePoint);
}
Ok. Yes this is a homework assignment for University. I'm not looking just for the answer, I would like to know why this program gives me a segmentation fault and how to correct it.
I know the error is in the Circle code, where I pass a pointer to the circlePOint in the constructor for the Circle class. I dont know why it generates a seg fault. I hope someone can provide some insight. Thanks.
Sorry if the code is messy. Had a hard time pasting it into here properly with 4 spaces and all that.
middlePoint is not allocated in your second Circle constructor. You are assigning a value to it before giving it some memory. As an aside, I don't see why anything there needs to be a pointer.
Why do you use pointers to Points inside your classes at all? You only generate memory leaks this way and (without your own copy operations) cause problems with as the midpoints could be shared by different circles.
PS: And it's not needed to have a PI value (even as non-const) in every circle - just use the constant from (afair) cmath for it.