| 1 |
///////////////////////////////////////////////////////////// |
| 2 |
// // |
| 3 |
// Copyright (c) 2007-2017 by The University of Queensland // |
| 4 |
// Centre for Geoscience Computing // |
| 5 |
// http://earth.uq.edu.au/centre-geoscience-computing // |
| 6 |
// // |
| 7 |
// Primary Business: Brisbane, Queensland, Australia // |
| 8 |
// Licensed under the Open Software License version 3.0 // |
| 9 |
// http://www.apache.org/licenses/LICENSE-2.0 // |
| 10 |
// // |
| 11 |
///////////////////////////////////////////////////////////// |
| 12 |
|
| 13 |
#include "Shape.h" |
| 14 |
#include <stdlib.h> |
| 15 |
#include <cmath> |
| 16 |
|
| 17 |
using std::cos; |
| 18 |
using std::sin; |
| 19 |
|
| 20 |
Shape::Shape() { |
| 21 |
this->pitch=0; |
| 22 |
this->yaw=0; |
| 23 |
this->roll=0; |
| 24 |
this->randomOrientation = 0; |
| 25 |
} |
| 26 |
|
| 27 |
Shape::~Shape() { |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Tell the shape to be randomly orientated. This will make every object |
| 33 |
* have a random orientation |
| 34 |
* \param i 1 for using random orientation, 0 to disable |
| 35 |
*/ |
| 36 |
void Shape::makeOrientationRandom(int i) { |
| 37 |
this->randomOrientation = i; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Returns 1 if the shape is to be randomly orientated |
| 42 |
* \returns 1 if shape is to be randomly orientated |
| 43 |
*/ |
| 44 |
int Shape::useRandomOrientation() { |
| 45 |
return this->randomOrientation; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
/** |
| 50 |
* Sets a random orientation. Note that this will be run before every |
| 51 |
* insert if the appropriate function is called. |
| 52 |
*/ |
| 53 |
void Shape::setRandomOrientation() { |
| 54 |
setRandomPitch(); |
| 55 |
setRandomYaw(); |
| 56 |
setRandomRoll(); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Set a random pitch to the object |
| 61 |
*/ |
| 62 |
void Shape::setRandomPitch() { |
| 63 |
this->pitch = (rand() % 180) - 90; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Set a random yaw to the object |
| 68 |
*/ |
| 69 |
void Shape::setRandomYaw() { |
| 70 |
this->yaw = (rand() % 360) - 180; |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Set a random roll to the object |
| 75 |
*/ |
| 76 |
void Shape::setRandomRoll() { |
| 77 |
this->roll = (rand() % 360) - 180; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Rotate a point around the x, y and z axies. Rotation values are given |
| 82 |
* using setRoll functions etc. |
| 83 |
* \param point the point to rotate |
| 84 |
* \returns the rotated point |
| 85 |
*/ |
| 86 |
Vector3 Shape::rotatePoint(Vector3 point) { |
| 87 |
double roll = this->roll *M_PI/180; |
| 88 |
double yaw = this->yaw *M_PI/180; |
| 89 |
double pitch = this->pitch *M_PI/180; |
| 90 |
/* |
| 91 |
double x = (cos(yaw)*cos(roll)+sin(yaw)*sin(pitch)*sin(roll))* point.x() |
| 92 |
+ (-sin(yaw)*cos(pitch)) * point.y() |
| 93 |
+ (sin(yaw)*sin(pitch)*cos(roll)-cos(yaw)*sin(roll))* point.z(); |
| 94 |
double y = (sin(yaw)*cos(roll)-cos(yaw)*sin(pitch)*sin(roll))* point.x() |
| 95 |
+ (cos(yaw)*cos(pitch)) * point.y() |
| 96 |
+ (-cos(yaw)*sin(pitch)*cos(roll)-sin(yaw)*sin(roll))*point.z(); |
| 97 |
double z = (cos(pitch)*sin(roll))*point.x() |
| 98 |
+ (sin(pitch)*point.y()) |
| 99 |
+ (cos(pitch)*cos(roll))*point.y(); |
| 100 |
Vector3 newpoint(x,y,z); |
| 101 |
*/ |
| 102 |
Vector3 newpoint = point.rotate(Vector3(roll,yaw,pitch),Vector3(0,0,0)); |
| 103 |
return newpoint; |
| 104 |
} |
| 105 |
|
| 106 |
int Shape::bias() { return this->bias_factor; } |
| 107 |
|
| 108 |
void Shape::setBias(int i) { |
| 109 |
this->bias_factor = i; |
| 110 |
} |
| 111 |
|
| 112 |
void Shape::setPitch(double pitch) { this->pitch = pitch; } |
| 113 |
double Shape::getPitch() { return this->pitch; } |
| 114 |
void Shape::setYaw(double yaw) { this->yaw = yaw; } |
| 115 |
double Shape::getYaw() { return this->yaw; } |
| 116 |
void Shape::setRoll(double roll) { this->roll = roll; } |
| 117 |
double Shape::getRoll() { return this->roll; } |
| 118 |
|
| 119 |
|
| 120 |
void Shape::setBondTag(int tag) { bondTag = tag; } |
| 121 |
int Shape::getBondTag() { return bondTag; } |
| 122 |
void Shape::setParticleTag(int tag) { particleTag = tag; } |
| 123 |
int Shape::getParticleTag() { return particleTag; } |
| 124 |
|
| 125 |
|