Question: Please help me implement clip.cpp in c + + : #include #include #include #include #include vec.h static std::random _ device rd; static std::mt 1
Please help me implement clip.cpp in c: #include
#include
#include
#include
#include "vec.h
static std::randomdevice rd;
static std::mt mtrd;
static std::uniformrealdistribution dist;
inline double getrandreturn distmt;
static std::uniformintdistribution idist std::mt::max;
inline unsigned randintreturn idistmt;
template void fillrandvec& udouble adouble b
forint i;i Clipconst Triangle& tri;
inline bool inconst vec& p
forint i;i;i
ifstd::abspip
return false;
return true;
inline vec tovecconst vec& p
return vecpppp;
inline bool ptintriconst Triangle& t const vec& p
vec tatovectAutovectBtavtovectCtawtovecpta;
vec ncrossuv;
double adotwcrossvndotnn;
double bdotwcrossnudotnn;
double cstd::absdotnw;
return ce && ae && be && abe;
int mainint argc, char argv
bool pass true;
forint i;i;i
Triangle it;
fillrandit;
auto ctClipit;
Make sure the clipped triangles lie entirely inside the clipping volume.
forconst auto& t:ct
ifintAintBintC
std::cout "vertex of clipped triangle is outside clipping volume" std::endl;
std::cout "input itA itB itC std::endl;
std::cout "output tA tB tC std::endl;
pass false;
break;
ifpass break;
Sample a bunch of points on the original triangle and discard the
ones that are not in the clipping volume. Verify that the rest lie
inside some clipped triangle.
forint j;j;j
double agetrandbgetranda;
vec ptitAaitBitAbitCitA;
ifinpt continue;
bool okfalse;
forconst auto& t:ct
ifptintritpt
oktrue;
ifok
std::cout "point pt is inside original triangle and inside clipping volume but not inside any of the clipped triangles."
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
