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

3Dtriangle.C

Go to the documentation of this file.
00001 //----------------------------------------------------------------------
00002 //               The Motion Strategy Library (MSL)
00003 //----------------------------------------------------------------------
00004 //
00005 // Copyright (c) 1998-2000 Iowa State University and Steve LaValle.  
00006 // All Rights Reserved.
00007 // 
00008 // Permission to use, copy, and distribute this software and its 
00009 // documentation is hereby granted free of charge, provided that 
00010 // (1) it is not a component of a commercial product, and 
00011 // (2) this notice appears in all copies of the software and
00012 //     related documentation. 
00013 // 
00014 // Iowa State University and the author make no representations
00015 // about the suitability or fitness of this software for any purpose.  
00016 // It is provided "as is" without express or implied warranty.
00017 //----------------------------------------------------------------------
00018 
00019 #include "3Dtriangle.h"
00020 
00021 #include <LEDA/REDEFINE_NAMES.h>
00022 
00023 Triangle::Triangle(d3_point pt1, d3_point pt2, d3_point pt3){
00024   p1 = pt1;
00025   p2 = pt2;
00026   p3 = pt3;
00027 }
00028 
00029 
00030 Triangle::Triangle(){
00031   d3_point *p;
00032   p = new d3_point(0,0,0);
00033   p1 = *p;
00034   p2 = *p;
00035   p3 = *p;
00036 }
00037 
00038 
00039 Triangle::Triangle(const Triangle& p){
00040   p1 = p.p1;
00041   p2 = p.p2;
00042   p3 = p.p3;
00043 }
00044 
00045 
00046 list<Triangle> PolygonsToTriangles(const list<polygon> &pl,
00047                                    double thickness) {
00048   polygon p;
00049   segment s;
00050   point pt;
00051   d3_point p1,p2,p3;
00052   list<Triangle> tl;
00053 
00054   tl.clear();
00055 
00056   forall(p,pl) {
00057     // Make the sides
00058     forall_segments(s,p) {
00059       p1 = d3_point(s.xcoord1(),s.ycoord1(),0.0);
00060       p2 = d3_point(s.xcoord2(),s.ycoord2(),0.0);
00061       p3 = d3_point(s.xcoord2(),s.ycoord2(),thickness);
00062       tl.push(Triangle(p1,p2,p3));
00063     }
00064     forall_segments(s,p) {
00065       p1 = d3_point(s.xcoord1(),s.ycoord1(),thickness);
00066       p2 = d3_point(s.xcoord2(),s.ycoord2(),thickness);
00067       p3 = d3_point(s.xcoord1(),s.ycoord1(),0.0);
00068       tl.push(Triangle(p1,p3,p2));
00069       pt = s.start(); // Get a point for later
00070     }
00071     // Make the top
00072     forall_segments(s,p) {
00073       if ((s.start() != pt)&&(s.end() != pt)) {
00074         p1 = d3_point(s.xcoord1(),s.ycoord1(),thickness);
00075         p2 = d3_point(s.xcoord2(),s.ycoord2(),thickness);
00076         p3 = d3_point(pt.xcoord(),pt.ycoord(),thickness);
00077         tl.push(Triangle(p1,p2,p3));
00078       }
00079     }
00080    }
00081 
00082   return tl;
00083 }
00084 
00085 
00086 list<polygon> TrianglesToPolygons(const list<Triangle> &tl) {
00087   Triangle tr;
00088   polygon p;
00089   d3_point p1,p2,p3;
00090   list<polygon> pl;
00091   list<point> ptl;
00092 
00093   pl.clear();
00094 
00095   forall(tr,tl) {
00096     ptl.clear();
00097     ptl.push(point(tr.p1.xcoord(),tr.p1.ycoord()));
00098     ptl.push(point(tr.p2.xcoord(),tr.p2.ycoord()));
00099     ptl.push(point(tr.p3.xcoord(),tr.p3.ycoord()));
00100     p = polygon(ptl,polygon::NO_CHECK);
00101     pl.push(p);
00102   }
00103 
00104   return pl;
00105 }
00106 
00107 
00108 #include <LEDA/UNDEFINE_NAMES.h>
00109 
00110 
00111 
00112 
00113 
Motion Strategy Library


Web page maintained by Steve LaValle
Partial support provided by NSF CAREER Award IRI-970228 (LaValle), Honda Research, and Iowa State University.
Contributors: Anna Atramentov, Peng Cheng, James Kuffner, Steve LaValle, and Libo Yang.