Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Spherical Polygons

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Spherical Polygons


Chronological Thread 
  • From: Monique Teillaud <>
  • To:
  • Subject: Re: [cgal-discuss] Spherical Polygons
  • Date: Sun, 25 Sep 2011 08:34:21 +0200

Dear Hamid,

I did no read all details in your message, but I see
typedef CGAL::Cartesian<long double> Kernel;
typedef CGAL::Nef_polyhedron_S2<Kernel> Nef_polyhedron;

whereas the manual says
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_S2_ref/Class_Nef_polyhedron_S2.html
-----
The first parameter requires one of the following exact kernels: Homogeneous, Simple_homogeneous parametrized with Gmpz, leda_integer or any other number type modeling ℤ, or Cartesian, Simple_cartesian parametrized with Gmpq, leda_rational,Quotient<Gmpz> or any other number type modeling ℚ.
-----

Using an exact kernel, as indicated in the manual, would probably help.

Best regards,
Monique
--
Monique Teillaud
INRIA Sophia Antipolis - Méditerranée
http://www.inria.fr/sophia/members/Monique.Teillaud/

Le 24/09/11 22:21, Hamid Laga a écrit :
Dear All,

I am new CGAL and want to use the provided spherical geometry tools
(Nef_polyhedron_S2 for example).

I have the following problem:
# Given two great circles (each one defined with two points on the sphere)
# I want to find the Nef_polyhedron_S2 that is the intersection of the two.

It is supposed to be simple with CGAL but I am getting the following
exception:
CGAL error: assertion violation
Expression: orientation(pred, p_sweep) == 0
File: ... cgal-3.8\include\nef_2\segment_overlay_traits.h
Line 752

Here is the minimal code
================
// CGAL
#include<CGAL/Gmpz.h>
#include<CGAL/Gmpzf.h>
#include<CGAL/MP_Float.h>
//#include<CGAL/Homogeneous.h>
#include<CGAL/Cartesian.h>
#include<CGAL/Nef_polyhedron_S2.h>

// STL
#include<iostream>
#include<fstream>
#include<vector>


using namespace std;

//typedef CGAL::Gmpq FT;
typedef CGAL::Gmpzf FT;

typedef CGAL::Cartesian<long double> Kernel;
typedef CGAL::Nef_polyhedron_S2<Kernel> Nef_polyhedron;
typedef Nef_polyhedron::Sphere_point Sphere_point;
typedef Nef_polyhedron::Sphere_segment Sphere_segment;
typedef Nef_polyhedron::Sphere_circle Sphere_circle;
typedef Nef_polyhedron::SVertex_const_handle SVertex_const_handle;
typedef Nef_polyhedron::SFace_const_iterator SFace_const_iterator;
typedef Nef_polyhedron::SFace_cycle_const_iterator SFace_cycle_const_iterator;

vector<double> CROSS3_(vector<double> v1, vector<double> v2){

vector<double> u(3);
u[0] = v1[1]*v2[2] - v1[2]*v2[1];
u[1] = v1[2]*v2[0] - v1[0]*v2[2];
u[2] = v1[0]*v2[1] - v1[1]*v2[0];

return u;
}
double NORM_(vector<double> u){

double the_norm = 0.0;

for (int i=0; i<u.size(); i++)
the_norm += u[i] * u[i];
return sqrt(the_norm);
}

int main(int argc, char **argv) {
try{

// First segment (p1, p2), the cond segment is (p2, p3)
std::vector<double> p1(3);
p1[0] = -0.857442; p1[1] = -0.326894; p1[2] = 0.397408;
// p1[0] = 1; p1[1] = 0; p1[2] = 0;
double nn =NORM_(p1);
p1[0] = p1[0] / nn; p1[1] = p1[1] / nn; p1[2] = p1[2]
/
nn;

std::vector<double> p2(3);
p2[0] = -0.958721; p2[1] = -0.094622; p2[2] = 0.268144;
// p2[0] = 0; p2[1] = 1; p2[2] = 0;
nn = NORM_(p2);
p2[0] = p2[0] / nn; p2[1] = p2[1] / nn; p2[2] = p2[2]
/
nn;


std::vector<double> p3(3);
p3[0] = -0.999944; p3[1] = -0.006510; p3[2] = 0.008326;
// p3[0] = 0; p3[1] = 0; p3[2] = 1;
nn =NORM_(p3);
p3[0] = p3[0] / nn; p3[1] = p3[1] / nn; p3[2] = p3[2]
/
nn;

// Equation of the plane spanned by (0, 0, 0) and p1, p2
std::vector<double> q = CROSS3_(p1, p2);
double NORM_Q = NORM_(q);
q[0] = q[0] / NORM_Q ;
q[1] = q[1] / NORM_Q ;
q[2] = q[2] / NORM_Q ;

Sphere_circle circle0((long double)q[0], (long double)q[1],
(long double)q[2]);
Nef_polyhedron sphKernel(circle0); //,
Nef_polyhedron::EXCLUDED);

// Equation of the plane spanned by (0, 0, 0) and p2, p3
std::vector<double> p = CROSS3_(p2, p3);
double NORM_P = NORM_(p);
p[0] = p[0] / NORM_P;
p[1] = p[1] / NORM_P;
p[2] = p[2] / NORM_P;

Sphere_circle circle1((long double)p[0], (long double)p[1],
(long double)p[2]); //q1, q2);


sphKernel = sphKernel * Nef_polyhedron(circle1); //,
Nef_polyhedron::EXCLUDED); //sphKernel.intersection(circle); // * circle;

printf("Done.");
getchar();
}
catch( std::bad_alloc& ) {
std::cerr<< "Error: out of memory!\n"<< std::endl;
return 1;
}
catch( std::exception& x ) {
std::cerr<< "Error: "<< x.what()<< std::endl;
return 1;
}
catch( ... ) {
std::cerr<< "Fatal! Unknown error!\n";
return 1;
}


}
==============================





Archive powered by MHonArc 2.6.16.

Top of Page