-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from gergondet/topic/Cylinder
Add S_Cylinder
- Loading branch information
Showing
7 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef _S_CYLINDER_H | ||
#define _S_CYLINDER_H | ||
|
||
#include <sch/S_Object/S_ObjectNormalized.h> | ||
|
||
namespace sch | ||
{ | ||
class S_Cylinder : | ||
public S_ObjectNormalized | ||
{ | ||
public: | ||
SCH_API S_Cylinder(Point3 p1, Point3 p2, Scalar radius); | ||
SCH_API ~S_Cylinder(); | ||
|
||
SCH_API const Point3 & getP1() const; | ||
|
||
SCH_API const Point3 & getP2() const; | ||
|
||
SCH_API Scalar getRadius() const; | ||
|
||
protected: | ||
SCH_API virtual Point3 l_Support(const Vector3& v, int& lastFeature)const; | ||
SCH_API virtual S_ObjectType getType() const; | ||
|
||
Point3 p1_, p2_; | ||
|
||
Vector3 normal_; | ||
|
||
Scalar radius_; | ||
}; | ||
} | ||
#endif //_S_CYLINDER_H | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,7 +230,8 @@ namespace sch | |
TSTP_BV_WithPolyhedron, | ||
TPoint, | ||
TCapsule, | ||
TCone | ||
TCone, | ||
TCylinder | ||
}; | ||
|
||
/*! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <sch/S_Object/S_Cylinder.h> | ||
|
||
using namespace sch; | ||
|
||
S_Cylinder::S_Cylinder(Point3 p1, Point3 p2, Scalar radius): p1_(p1),p2_(p2),radius_(radius) | ||
{ | ||
normal_ = p2_ - p1_; | ||
assert(normal_.norm() != 0); | ||
normal_.normalize(); | ||
} | ||
|
||
S_Cylinder::~S_Cylinder() | ||
{ | ||
} | ||
|
||
Point3 S_Cylinder::l_Support(const Vector3& v, int& /*lastFeature*/)const | ||
{ | ||
Point3 d = p1_; | ||
double dot = normal_ * v; | ||
if (dot > 0) | ||
{ | ||
d = p2_; | ||
} | ||
Vector3 proj = v - normal_ * dot; | ||
double proj_norm = proj.norm(); | ||
if(proj_norm != 0) | ||
{ | ||
return d + proj * (radius_ / proj_norm); | ||
} | ||
else | ||
{ | ||
return d; | ||
} | ||
} | ||
|
||
S_Object::S_ObjectType S_Cylinder::getType() const | ||
{ | ||
return S_Object::TCylinder; | ||
} | ||
|
||
const Point3 & S_Cylinder::getP1() const | ||
{ | ||
return p1_; | ||
} | ||
|
||
const Point3 & S_Cylinder::getP2() const | ||
{ | ||
return p2_; | ||
} | ||
|
||
Scalar S_Cylinder::getRadius() const | ||
{ | ||
return radius_; | ||
} |