added basic constructor with corner initializer
This commit is contained in:
parent
10c35064dd
commit
e174292201
@ -3,9 +3,9 @@
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::cout << "Hello, world!" << std::endl;
|
||||
Volumes::Block block;
|
||||
Vector::Vector3 vec(1,2,3);
|
||||
Vector::Vector3 vec2(2,1,3);
|
||||
Volumes::Block block(vec,1,1,1);
|
||||
std::cout<<vec<<std::endl;
|
||||
std::cout<<vec.len()<<std::endl;
|
||||
vec*=2;
|
||||
@ -22,5 +22,6 @@ int main(int argc, char **argv) {
|
||||
vec-=vec;
|
||||
std::cout<<vec<<std::endl;
|
||||
std::cout<<vec.len()<<std::endl;
|
||||
std::cout<<block<<std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
@ -10,10 +10,31 @@
|
||||
namespace Volumes{
|
||||
class Block{
|
||||
public:
|
||||
Block(const Vector::Vector3& v1, double x, double y, double z):corners{v1,
|
||||
v1+Vector::Vector3(x,0,0),
|
||||
v1+Vector::Vector3(x,y,0),
|
||||
v1+Vector::Vector3(0,y,z),v1,
|
||||
v1+Vector::Vector3(x,y,z),
|
||||
v1+Vector::Vector3(x,0,z),
|
||||
v1+Vector::Vector3(0,0,z)}{};
|
||||
virtual ~Block() = default;
|
||||
|
||||
double getVolume();
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const Block& v){
|
||||
os<<"[";
|
||||
short count=0;
|
||||
for(Vector::Vector3 corner:v.corners){
|
||||
count++;
|
||||
os<<corner;
|
||||
if(count<8) {
|
||||
os << std::endl;
|
||||
}
|
||||
}
|
||||
os<<"]";
|
||||
return os;
|
||||
}
|
||||
|
||||
private:
|
||||
Vector::Vector3 corners[8];
|
||||
};
|
||||
|
@ -5,7 +5,9 @@
|
||||
|
||||
namespace Volumes{
|
||||
double Block::getVolume() {
|
||||
|
||||
return 0;
|
||||
Vector::Vector3 x=corners[1]-corners[0];
|
||||
Vector::Vector3 y=corners[3]-corners[0];
|
||||
Vector::Vector3 z=corners[7]-corners[0];
|
||||
return x.len()*y.len()*z.len();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user