Subject: CGAL users discussion list
List archive
- From: Pedro Machado Manhães de Castro <>
- To:
- Subject: Re: Re: Re: [cgal-discuss] how to output a point's coordinate
- Date: Fri, 6 Mar 2009 14:18:18 +0100
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=v2oES4jGm6zv4wOyYne6FD2tIpZpojx2gKJd5eimmnkY48j4/7uI9r/hrd3IHCtzVW ji6Rs4orsaH0xQ7x4Wi7nmAQWcIfni5HAKgs69CfzapITWEwlLR2rFCqIBSfy4d/UsGU kvWvLc2QQgCLPyek+U20U3as/mlnFzKOwhgm4=
Hi Zengming,
Those are the "ugly" output of the root_of_2 function, you probably would prefer to output like that:
#include <CGAL/Exact_spherical_kernel_3.h>
#include <CGAL/Spherical_kernel_intersections.h>
#include <CGAL/Circular_arc_point_3.h>
typedef CGAL::Exact_spherical_kernel_3 Spherical_k;
typedef CGAL::Point_3<Spherical_k> Point_3;
typedef CGAL::Sphere_3<Spherical_k> Sphere_3;
typedef std::pair< CGAL::Circular_arc_point_3<Spherical_k>, unsigned> Point_pair;
int main() {
Sphere_3 s1 = Sphere_3(Point_3(1.0,0.0,0.0), 1.0);
Sphere_3 s2 = Sphere_3(Point_3(0.0,1.0,0.0), 1.0);
Sphere_3 s3 = Sphere_3(Point_3(0.0,0.0,1.0), 1.0);
std::vector< CGAL::Object > intersecs;
CGAL::intersection(s1, s2, s3, std::back_inserter(intersecs));
std::cout<<intersecs.size()<<std::endl;
const Point_pair *p[2];
for(int i=0; i<intersecs.size(); ++i)
{
if( p[i] = CGAL::object_cast<Point_pair>(&intersecs[i]) )
{
std::cout<<p[i]->second<<std::endl;
//std::cout<<(p[i]->first).x()<<" "<<(p[i]->first).y()<<" "<<(p[i]->first).z()<<" "<<std::endl;
double x = CGAL_NTS to_double((p[i]->first).x());
double y = CGAL_NTS to_double((p[i]->first).y());
double z = CGAL_NTS to_double((p[i]->first).z());
std::cout << x << " " << y << " " << z << std::endl;
}
}
return 0;
}
However when you convert to double you lose the accuracy, be aware of that.
Best regards,
Pedro
On Fri, Mar 6, 2009 at 2:00 PM, zengming <> wrote:
Hi, PedroI rewrite the program, but can not get the right answer.This is the program:==============================================#include <CGAL/Exact_spherical_kernel_3.h>#include <CGAL/Spherical_kernel_intersections.h>
#include <CGAL/Circular_arc_point_3.h>typedef CGAL::Exact_spherical_kernel_3 Spherical_k;typedef std::pair< CGAL::Circular_arc_point_3<Spherical_k>, unsigned> Point_pair;
typedef CGAL::Point_3<Spherical_k> Point_3;
typedef CGAL::Sphere_3<Spherical_k> Sphere_3;int main() {Sphere_3 s1 = Sphere_3(Point_3(1.0,0.0,0.0), 1.0);
Sphere_3 s2 = Sphere_3(Point_3(0.0,1.0,0.0), 1.0);
Sphere_3 s3 = Sphere_3(Point_3(0.0,0.0,1.0), 1.0);std::vector< CGAL::Object > intersecs;const Point_pair *p[2];
CGAL::intersection(s1, s2, s3, std::back_inserter(intersecs));
std::cout<<intersecs.size()<<std::endl;
for(int i=0; i<intersecs.size(); ++i)
{
if( p[i] = CGAL::object_cast<Point_pair>(&intersecs[i]) )
{
std::cout<<p[i]->second<<std::endl;
std::cout<<(p[i]->first).x()<<" "<<(p[i]->first).y()<<" "<<(p[i]->first).z()<<" "<<std::endl;
}
}return 0;
}===============================================and follow is the output:2
1
0256/768 -4/1 0.1875/27 01024/3072 -4/1 0.1875/27 01024/3072 -4/1 0.1875/27
1
0256/768 4/1 0.1875/27 01024/3072 4/1 0.1875/27 01024/3072 4/1 0.1875/27Press any key to continue . . .===============================================In my case, 3 spheres are [center=(1.0, 0.0, 0.0), radius=1.0], [center=(0.0, 1.0, 0.0), radius=1.0],[center=(0.0, 0.0, 1.0), radius=1.0], I figured out that they intersect in points (0, 0, 0) and (0.67, 0.67, 0.67).In order to get the result, how should I write the program, and if I want to get the results in type double, how should i do?2009-03-06
zengming
发件人: Pedro_Machado_Manh�es_de_Castro发送时间: 2009-03-06 16:51:34收件人:抄送:主题: Re: Re: [cgal-discuss] how to output a point's coordinateHi!
I think that what you probably want is a Circular_arc_point_3.
Since this line:
assign(pt3, intersecs[0]);
should not work as the type of pt3 is a Point_3 and the type of intersecs[0] is Circular_arc_point_3, your pt3 may keep to be uninitialized.
"Should not work" in this case means "assign(pt3, intersecs[0]);" will return 0, but wont assign anithing to pt3.
As your intersection (considering r = 1) is probably (0, 0, 0), that would "work" (because the value of an uninitialized pt3 would be (0,0,0) ).
The main difference between Point_3 and Circular_arc_point_3 is that Point_3 stores rationals as coordinates while Circular_arc_point_3 stores algebraic numbers of degree 2 (Root_of_2).
This happens because the intersection between 3 rational spheres (or 2 rational circles) may not be representable by rationals, however they are representable by Root_of_2.
By rational spheres (circles) I mean spheres with a rational center (placed on rational coordinates) and with rational squared radius.
So look at what Tom said and prefer using Circular_arc_point_3 instead of Point_3, because only the first one really works.
Pedro
PS: don't overlook the case where the intersection of three spheres can be a Circle_3 or even a Sphere_3.
On Fri, Mar 6, 2009 at 9:22 AM, zengming <> wrote:
I saw the result by your method, thanks!2009-03-06
zengming
发件人: Samuel Hornus发送时间: 2009-03-06 16:13:53收件人:抄送:主题: Re: [cgal-discuss] how to output a point's coordinate"zengming" < > wrote:> Point_3 pt3;> assign(pt3, intersecs[0]);>> //how can I output the coordinate of point pt3?The following should work:std::cout < < pt3;--sam--You are currently subscribed to cgal-discuss.To unsubscribe or access the archives, go to
- [cgal-discuss] how to output a point's coordinate, zengming, 03/06/2009
- Re: [cgal-discuss] how to output a point's coordinate, Samuel Hornus, 03/06/2009
- Re: Re: [cgal-discuss] how to output a point's coordinate, zengming, 03/06/2009
- Re: Re: [cgal-discuss] how to output a point's coordinate, Pedro Machado Manhães de Castro, 03/06/2009
- Re: Re: Re: [cgal-discuss] how to output a point's coordinate, zengming, 03/06/2009
- Re: Re: Re: [cgal-discuss] how to output a point's coordinate, zengming, 03/06/2009
- Re: Re: Re: [cgal-discuss] how to output a point's coordinate, Pedro Machado Manhães de Castro, 03/06/2009
- Re: Re: Re: [cgal-discuss] how to output a point's coordinate, zengming, 03/06/2009
- Re: Re: Re: [cgal-discuss] how to output a point's coordinate, Pedro Machado Manhães de Castro, 03/06/2009
- [cgal-discuss] How to rotate Segment_2, naresh, 03/06/2009
- [cgal-discuss] Sweep Line Running slow, naresh, 03/07/2009
- Re: [cgal-discuss] Sweep Line Running slow, Ophir Setter, 03/07/2009
- [cgal-discuss] Point Rotation problem or Bug ?, naresh, 03/12/2009
- [cgal-discuss] How to find center of mass and principal inertial axis of 3D model?, Samay Kumar, 03/13/2009
- Re: [cgal-discuss] How to find center of mass and principal inertial axis of 3D model?, naresh, 03/13/2009
- Re: [cgal-discuss] How to find center of mass and principal inertial, Ashwin N, 03/14/2009
- Re: [cgal-discuss] How to find center of mass and principal inertial, Pierre Alliez, 03/25/2009
- Re: [cgal-discuss] Point Rotation problem or Bug ?, Ashwin N, 03/14/2009
- [cgal-discuss] Point Rotation problem or Bug ?, naresh, 03/12/2009
- Re: [cgal-discuss] Sweep Line Running slow, Ophir Setter, 03/07/2009
- [cgal-discuss] Sweep Line Running slow, naresh, 03/07/2009
- Re: Re: [cgal-discuss] how to output a point's coordinate, Pedro Machado Manhães de Castro, 03/06/2009
- Re: Re: [cgal-discuss] how to output a point's coordinate, zengming, 03/06/2009
- Re: [cgal-discuss] how to output a point's coordinate, Samuel Hornus, 03/06/2009
Archive powered by MHonArc 2.6.16.