Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you write the clipping algorithm in this function: std::vector Clip ( const Triangle& tri ) { using this vec.h file: #ifndef

can you write the clipping algorithm in this function: "std::vector Clip(const Triangle& tri)
{" using this vec.h file: "#ifndef __vec__
#define __vec__
#include
#include
#include
static const double pi =4* atan(1.0);
template struct vec;
template T dot(const vec& u,const vec& v);
template
struct vec
{
T x[n];
vec()
{make_zero();}
explicit vec(const T& a)
{assert(n ==1);x[0]=a;}
vec(const T& a, const T& b)
{assert(n ==2);x[0]=a;x[1]=b;}
vec(const T& a, const T& b, const T& c)
{assert(n ==3);x[0]=a;x[1]=b;x[2]=c;}
template
explicit vec(const vec& v)
{for(int i =0; i < n; i++) x[i]=(T)v.x[i];}
void make_zero()
{fill(0);}
void fill(T value)
{for(int i =0; i < n; i++) x[i]= value;}
vec& operator +=(const vec& v)
{for(int i =0; i < n; i++) x[i]+= v.x[i]; return *this;}
vec& operator -=(const vec& v)
{for(int i =0; i < n; i++) x[i]-= v.x[i]; return *this;}
vec& operator *=(const vec& v)
{for(int i =0; i < n; i++) x[i]*= v.x[i]; return *this;}
vec& operator /=(const vec& v)
{for(int i =0; i < n; i++) x[i]/= v.x[i]; return *this;}
vec& operator +=(const T& c)
{for(int i =0; i < n; i++) x[i]+= c; return *this;}
vec& operator -=(const T& c)
{for(int i =0; i < n; i++) x[i]-= c; return *this;}
vec& operator *=(const T& c)
{for(int i =0; i < n; i++) x[i]*= c; return *this;}
vec& operator /=(const T& c)
{for(int i =0; i < n; i++) x[i]/= c; return *this;}
vec operator +() const
{return *this;}
vec operator -() const
{vec r; for(int i =0; i < n; i++) r[i]=-x[i]; return r;}
vec operator +(const vec& v) const
{vec r; for(int i =0; i < n; i++) r[i]= x[i]+ v.x[i]; return r;}
vec operator -(const vec& v) const
{vec r; for(int i =0; i < n; i++) r[i]= x[i]- v.x[i]; return r;}
vec operator *(const vec& v) const
{vec r; for(int i =0; i < n; i++) r[i]= x[i]* v.x[i]; return r;}
vec operator /(const vec& v) const
{vec r; for(int i =0; i < n; i++) r[i]= x[i]/ v.x[i]; return r;}
vec operator +(const T& c) const
{vec r; for(int i =0; i < n; i++) r[i]= x[i]+ c; return r;}
vec operator -(const T& c) const
{vec r; for(int i =0; i < n; i++) r[i]= x[i]- c; return r;}
vec operator *(const T& c) const
{vec r; for(int i =0; i < n; i++) r[i]= x[i]* c; return r;}
vec operator /(const T& c) const
{vec r; for(int i =0; i < n; i++) r[i]= x[i]/ c; return r;}
const T& operator[](int i) const
{return x[i];}
T& operator[](int i)
{return x[i];}
T magnitude_squared() const
{return dot(*this,*this);}
T magnitude() const
{return sqrt(magnitude_squared());}
// Be careful to handle the zero vector gracefully
vec normalized() const
{T mag = magnitude(); if(mag) return *this / mag; vec r; r[0]=1; return r;};
};
template
vec operator *(const T& c, const vec& v)
{return v*c;}
template
T dot(const vec & u, const vec & v)
{
T r =0;
for(int i =0; i < n; i++) r += u.x[i]* v.x[i];
return r;
}
template
vec cross(const vec & u, const vec & v)
{
return vec (
u[1]* v[2]- u[2]* v[1],
u[2]* v[0]- u[0]* v[2],
u[0]* v[1]- u[1]* v[0]);
}
template
vec componentwise_max(const vec& a, const vec& b)
{
vec r;
for(int i=0; i
vec componentwise_min(const vec& a, const vec& b)
{
vec r;
for(int i=0; i
std::ostream& operator <<(std::ostream& out, const vec & u)
{
out <<'(';
for(int i =0; i < n; i++)
{
if(i) out <<'';
out << u[i];
}
out <<')';
return out;
}
template
std::istream& operator >>(std::istream& in, vec & u)
{
for(int i =0; i < n; i++)
{
in >> u[i];
}
return in;
}
using std::abs;
template
vec abs(const vec & u)
{
vec r;
for(int i =0; i < n; i++)
r[i]= std::abs(u[i]);
return r;
}
typedef vec vec2;
typedef vec vec3;
typedef vec vec4;
typedef vec ivec2;
typedef vec ivec3;
typedef vec ivec4;
#endif" and this file that contains test cases: "#include
#include
#include
#include
#include "vec.h"
static std::random_device rd;
static std::mt19937 mt(rd());
static std::uniform_real_distribution<> dist(0,1);
inline double get_rand(){return dist(mt);}
static std::uniform_int_distribution"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

Students also viewed these Databases questions

Question

2. Define communication.

Answered: 1 week ago