From 4e9510bcaad142ecfb91e74fddf3aa19aea7334e Mon Sep 17 00:00:00 2001 From: Susan Hert Date: Wed, 7 Feb 2001 17:55:18 +0000 Subject: [PATCH] added volume, squared_area function --- Packages/H3/changes.txt | 1 + Packages/H3/include/CGAL/Iso_cuboidH3.h | 11 +++++-- Packages/H3/include/CGAL/TetrahedronH3.h | 38 ++++++++++++++++++++---- Packages/H3/include/CGAL/TriangleH3.h | 14 +++++++++ 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/Packages/H3/changes.txt b/Packages/H3/changes.txt index 65a47c92020..43bef06b16d 100644 --- a/Packages/H3/changes.txt +++ b/Packages/H3/changes.txt @@ -1,5 +1,6 @@ 2.16 (?? ??? 2001) - Macro cleanups. +- squared_area() and volume() functions added 2.15 (22 Jan 2001) - CGAL::compare -> CGAL_NTS compare in SphereH3 to fix a warning. diff --git a/Packages/H3/include/CGAL/Iso_cuboidH3.h b/Packages/H3/include/CGAL/Iso_cuboidH3.h index c6c9fe604b0..2f3e1e143ed 100644 --- a/Packages/H3/include/CGAL/Iso_cuboidH3.h +++ b/Packages/H3/include/CGAL/Iso_cuboidH3.h @@ -56,8 +56,7 @@ public: bool has_on_bounded_side(const PointH3& p) const; bool has_on_unbounded_side(const PointH3& p) const; bool is_degenerate() const; - Bbox_2 - bbox() const; + Bbox_2 bbox() const; FT xmin() const; FT ymin() const; FT zmin() const; @@ -65,6 +64,7 @@ public: FT ymax() const; FT zmax() const; + FT volume() const; }; @@ -193,6 +193,12 @@ FT Iso_cuboidH3::zmax() const { return FT( max().hz() ) / FT( max().hw() ); } +template < class FT, class RT > +inline +FT +Iso_cuboidH3::volume() const +{ return (xmax() - xmin()) * (ymax() - ymin()) * (zmax() - zmin()); } + template < class FT, class RT > CGAL_KERNEL_LARGE_INLINE PointH3 @@ -224,6 +230,7 @@ PointH3 Iso_cuboidH3::operator[](int i) const { return vertex(i); } + template < class FT, class RT > CGAL_KERNEL_MEDIUM_INLINE Bounded_side diff --git a/Packages/H3/include/CGAL/TetrahedronH3.h b/Packages/H3/include/CGAL/TetrahedronH3.h index cbfe9150ae3..83b1f254c27 100644 --- a/Packages/H3/include/CGAL/TetrahedronH3.h +++ b/Packages/H3/include/CGAL/TetrahedronH3.h @@ -70,6 +70,8 @@ public: bool operator==(const TetrahedronH3 &t) const; bool operator!=(const TetrahedronH3 &t) const; Bbox_3 bbox() const; + FT volume() const; + TetrahedronH3 transform(const Aff_transformationH3 &t) const; Orientation orientation() const; @@ -102,7 +104,6 @@ TetrahedronH3::TetrahedronH3(const PointH3 &p, {} - template < class FT, class RT > CGAL_KERNEL_INLINE bool @@ -127,12 +128,12 @@ TetrahedronH3::operator==(const TetrahedronH3 &t) const return V1 == V2; } - template < class FT, class RT > inline bool TetrahedronH3::operator!=(const TetrahedronH3 &t) const { return !(*this == t); } + template < class FT, class RT > CGAL_KERNEL_INLINE PointH3 @@ -316,6 +317,33 @@ TetrahedronH3::bbox() const vertex(0).bbox() + vertex(1).bbox() + vertex(2).bbox() + vertex(3).bbox(); } +template < class FT, class RT > +CGAL_KERNEL_MEDIUM_INLINE +FT +TetrahedronH3::volume() const +{ + VectorH3 vec1 = vertex(1) - vertex(0); + VectorH3 vec2 = vertex(2) - vertex(0); + VectorH3 vec3 = vertex(3) - vertex(0); + + // first compute (vec1.hw * vec2.hw * vec3.hw * det(vec1, vec2, vec3)) + // then divide by (6 * vec1.hw * vec2.hw * vec3.hw) + FT w123 = vec1.hw() * vec2.hw() * vec3.hw(); + FT hx1 = vec1.hx(); + FT hy1 = vec1.hy(); + FT hz1 = vec1.hz(); + FT hx2 = vec2.hx(); + FT hy2 = vec2.hy(); + FT hz2 = vec2.hz(); + FT hx3 = vec3.hx(); + FT hy3 = vec3.hy(); + FT hz3 = vec3.hz(); + + return ( (hx1 * (hy2 * hz3 - hy3 * hz2)) + - (hy1 * (hx2 * hz3 - hx3 * hz2)) + + (hz1 * (hx2 * hy3 - hx3 * hy2)))/ (FT(6) * w123); +} + template < class FT, class RT > inline TetrahedronH3 @@ -323,9 +351,9 @@ TetrahedronH3:: transform(const Aff_transformationH3 &t) const { return TetrahedronH3(t.transform(vertex(0)), - t.transform(vertex(1)), - t.transform(vertex(2)), - t.transform(vertex(3))); + t.transform(vertex(1)), + t.transform(vertex(2)), + t.transform(vertex(3))); } diff --git a/Packages/H3/include/CGAL/TriangleH3.h b/Packages/H3/include/CGAL/TriangleH3.h index 63e35df0184..28532db61b4 100644 --- a/Packages/H3/include/CGAL/TriangleH3.h +++ b/Packages/H3/include/CGAL/TriangleH3.h @@ -56,6 +56,8 @@ public: PointH3 vertex(int i) const; PointH3 operator[](int i) const; + FT squared_area() const; + Bbox_3 bbox() const; }; @@ -109,12 +111,24 @@ TriangleH3::vertex(int i) const } // return PointH3(); } + template < class FT, class RT > inline PointH3 TriangleH3::operator[](int i) const { return vertex(i); } +template < class FT, class RT > +CGAL_KERNEL_MEDIUM_INLINE +FT +TriangleH3::squared_area() const +{ + VectorH3 v1 = vertex(1) - vertex(0); + VectorH3 v2 = vertex(2) - vertex(0); + VectorH3 v3 = cross_product(v1, v2); + return (v3 * v3)/FT(4); +} + template < class FT, class RT > CGAL_KERNEL_INLINE PlaneH3