Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

set_point.cc

00001 #include <CGAL/Gmpz.h>
00002 #include <CGAL/Homogeneous.h>
00003 
00004 #include "set_point.h"
00005 
00006 void
00007 set_point( CGAL::Point_3< CGAL::Homogeneous<CGAL::Gmpz> >& p,
00008            double x, double y, double z )
00009 {
00010     mpq_t Qx, Qy, Qz;
00011     mpz_t Zx, Zy, Zz, Zw;
00012 
00013     mpq_init(Qx);
00014     mpq_set_d( Qx, x );
00015 
00016     mpq_init(Qy);
00017     mpq_set_d( Qy, y );
00018 
00019     mpq_init(Qz);
00020     mpq_set_d( Qz, z );
00021 
00022     /* let W be the least common multiple of the three denominators */
00023     mpz_init(Zw);
00024     mpz_lcm( Zw, mpq_denref(Qx), mpq_denref(Qy) );
00025     mpz_lcm( Zw, Zw, mpq_denref(Qz) );
00026 
00027     /* let X = Nx/Dx; then X = Nx'/W, where Nx' = Nx*(W/Dx)
00028        Compute Nx' and store in Zx.  Ditto for Zy, and Zz. */
00029 
00030     mpz_init(Zx);
00031     mpz_divexact( Zx, Zw, mpq_denref(Qx) );
00032     mpz_mul( Zx, Zx, mpq_numref(Qx) );
00033 
00034     mpz_init(Zy);
00035     mpz_divexact( Zy, Zw, mpq_denref(Qy) );
00036     mpz_mul( Zy, Zy, mpq_numref(Qy) );
00037 
00038     mpz_init(Zz);
00039     mpz_divexact( Zz, Zw, mpq_denref(Qz) );
00040     mpz_mul( Zz, Zz, mpq_numref(Qz) );
00041 
00042     p = CGAL::Point_3< CGAL::Homogeneous<CGAL::Gmpz> >( Zx, Zy, Zz, Zw );
00043 
00044     mpq_clear(Qx);
00045     mpq_clear(Qy);
00046     mpq_clear(Qz);
00047 
00048     mpz_clear(Zx);
00049     mpz_clear(Zy);
00050     mpz_clear(Zz);
00051     mpz_clear(Zw);
00052 }
00053 

Generated on Fri Oct 26 23:38:12 2001 for bicobj-intersection by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001