bool GlareSensor_Impl::aimAt(const Point3d& target) { Point3d position = this->position(); Vector3d vector = target - position; if (!vector.normalize()){ return false; } Vector3d yAxis(0,1,0); Vector3d rotationAxis = yAxis.cross(vector); if (!rotationAxis.normalize()){ return false; } double angle = getAngle(yAxis, vector); Transformation transformation = Transformation::rotation(rotationAxis, angle); EulerAngles eulerAngles = transformation.eulerAngles(); this->setPsiRotationAroundXAxis(eulerAngles.psi()); this->setThetaRotationAroundYAxis(eulerAngles.theta()); this->setPhiRotationAroundZAxis(eulerAngles.phi()); return true; }
bool GlareSensor_Impl::setTransformation(const openstudio::Transformation& transformation) { Vector3d translation = transformation.translation(); this->setPositionXCoordinate(translation.x()); this->setPositionYCoordinate(translation.y()); this->setPositionZCoordinate(translation.z()); EulerAngles eulerAngles = transformation.eulerAngles(); setPsiRotationAroundXAxis(radToDeg(eulerAngles.psi())); setThetaRotationAroundYAxis(radToDeg(eulerAngles.theta())); setPhiRotationAroundZAxis(radToDeg(eulerAngles.phi())); return true; }
bool PlanarSurfaceGroup_Impl::setTransformation(const openstudio::Transformation& transformation) { EulerAngles eulerAngles = transformation.eulerAngles(); if ((eulerAngles.psi() != 0) || (eulerAngles.theta() != 0)){ return false; } double dORN = -radToDeg(eulerAngles.phi()); this->setDirectionofRelativeNorth(dORN, false); Vector3d translation = transformation.translation(); this->setXOrigin(translation.x(), false); this->setYOrigin(translation.y(), false); this->setZOrigin(translation.z(), false); this->emitChangeSignals(); return true; }
bool IlluminanceMap_Impl::setTransformation(const openstudio::Transformation& transformation) { bool test; Vector3d translation = transformation.translation(); this->setOriginXCoordinate(translation.x()); this->setOriginYCoordinate(translation.y()); this->setOriginZCoordinate(translation.z()); EulerAngles eulerAngles = transformation.eulerAngles(); test = this->setPsiRotationAroundXAxis(radToDeg(eulerAngles.psi())); OS_ASSERT(test); test = this->setThetaRotationAroundYAxis(radToDeg(eulerAngles.theta())); OS_ASSERT(test); test = this->setPhiRotationAroundZAxis(radToDeg(eulerAngles.phi())); OS_ASSERT(test); return true; }
TEST_F(GeometryFixture, EulerAngles) { Transformation transformation; EulerAngles angles = transformation.eulerAngles(); EXPECT_EQ(0.0, angles.psi()); EXPECT_EQ(0.0, angles.theta()); EXPECT_EQ(0.0, angles.phi()); angles = EulerAngles(0,0,0); transformation = Transformation::rotation(angles); Matrix rotationMatrix = transformation.rotationMatrix(); ASSERT_EQ(static_cast<unsigned>(3), rotationMatrix.size1()); ASSERT_EQ(static_cast<unsigned>(3), rotationMatrix.size2()); EXPECT_EQ(1.0, rotationMatrix(0,0)); EXPECT_EQ(0.0, rotationMatrix(0,1)); EXPECT_EQ(0.0, rotationMatrix(0,2)); EXPECT_EQ(0.0, rotationMatrix(1,0)); EXPECT_EQ(1.0, rotationMatrix(1,1)); EXPECT_EQ(0.0, rotationMatrix(1,2)); EXPECT_EQ(0.0, rotationMatrix(2,0)); EXPECT_EQ(0.0, rotationMatrix(2,1)); EXPECT_EQ(1.0, rotationMatrix(2,2)); transformation = Transformation::translation(Vector3d(1,1,1)); angles = transformation.eulerAngles(); EXPECT_EQ(0.0, angles.psi()); EXPECT_EQ(0.0, angles.theta()); EXPECT_EQ(0.0, angles.phi()); transformation = Transformation::rotation(Vector3d(1,0,0), 1.0); angles = transformation.eulerAngles(); EXPECT_EQ(1.0, angles.psi()); EXPECT_EQ(0.0, angles.theta()); EXPECT_EQ(0.0, angles.phi()); angles = EulerAngles(1,0,0); transformation = Transformation::rotation(angles); rotationMatrix = transformation.rotationMatrix(); ASSERT_EQ(static_cast<unsigned>(3), rotationMatrix.size1()); ASSERT_EQ(static_cast<unsigned>(3), rotationMatrix.size2()); EXPECT_NEAR(1.0, rotationMatrix(0,0), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(0,1), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(0,2), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(1,0), 0.0001); EXPECT_NEAR(cos(1.0), rotationMatrix(1,1), 0.0001); EXPECT_NEAR(-sin(1.0), rotationMatrix(1,2), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(2,0), 0.0001); EXPECT_NEAR(sin(1.0), rotationMatrix(2,1), 0.0001); EXPECT_NEAR(cos(1.0), rotationMatrix(2,2), 0.0001); transformation = Transformation::rotation(Vector3d(0,1,0), 1.0); angles = transformation.eulerAngles(); EXPECT_EQ(0.0, angles.psi()); EXPECT_EQ(1.0, angles.theta()); EXPECT_EQ(0.0, angles.phi()); angles = EulerAngles(0,1,0); transformation = Transformation::rotation(angles); rotationMatrix = transformation.rotationMatrix(); ASSERT_EQ(static_cast<unsigned>(3), rotationMatrix.size1()); ASSERT_EQ(static_cast<unsigned>(3), rotationMatrix.size2()); EXPECT_NEAR(cos(1.0), rotationMatrix(0,0), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(0,1), 0.0001); EXPECT_NEAR(sin(1.0), rotationMatrix(0,2), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(1,0), 0.0001); EXPECT_NEAR(1.0, rotationMatrix(1,1), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(1,2), 0.0001); EXPECT_NEAR(-sin(1.0), rotationMatrix(2,0), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(2,1), 0.0001); EXPECT_NEAR(cos(1.0), rotationMatrix(2,2), 0.0001); transformation = Transformation::rotation(Vector3d(0,0,1), 1.0); angles = transformation.eulerAngles(); EXPECT_EQ(0.0, angles.psi()); EXPECT_EQ(0.0, angles.theta()); EXPECT_EQ(1.0, angles.phi()); angles = EulerAngles(0,0,1); transformation = Transformation::rotation(angles); rotationMatrix = transformation.rotationMatrix(); ASSERT_EQ(static_cast<unsigned>(3), rotationMatrix.size1()); ASSERT_EQ(static_cast<unsigned>(3), rotationMatrix.size2()); EXPECT_NEAR(cos(1.0), rotationMatrix(0,0), 0.0001); EXPECT_NEAR(-sin(1.0), rotationMatrix(0,1), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(0,2), 0.0001); EXPECT_NEAR(sin(1.0), rotationMatrix(1,0), 0.0001); EXPECT_NEAR(cos(1.0), rotationMatrix(1,1), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(1,2), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(2,0), 0.0001); EXPECT_NEAR(0.0, rotationMatrix(2,1), 0.0001); EXPECT_NEAR(1.0, rotationMatrix(2,2), 0.0001); Matrix matrix(4,4); matrix(0,0) = 0.5; matrix(0,1) = -0.1464; matrix(0,2) = 0.8536; matrix(1,0) = 0.5; matrix(1,1) = 0.8536; matrix(1,2) = -0.1464; matrix(2,0) = -0.7071; matrix(2,1) = 0.5; matrix(2,2) = 0.5; matrix(3,3) = 1.0; transformation = Transformation(matrix); angles = transformation.eulerAngles(); EXPECT_NEAR(boost::math::constants::pi<double>()/4.0, angles.psi(), 0.0001); EXPECT_NEAR(boost::math::constants::pi<double>()/4.0, angles.theta(), 0.0001); EXPECT_NEAR(boost::math::constants::pi<double>()/4.0, angles.phi(), 0.0001); angles = EulerAngles(boost::math::constants::pi<double>()/4.0, boost::math::constants::pi<double>()/4.0, boost::math::constants::pi<double>()/4.0); transformation = Transformation::rotation(angles); rotationMatrix = transformation.rotationMatrix(); EXPECT_NEAR(0.5, rotationMatrix(0,0), 0.0001); EXPECT_NEAR(-0.1464, rotationMatrix(0,1), 0.0001); EXPECT_NEAR(0.8536, rotationMatrix(0,2), 0.0001); EXPECT_NEAR(0.5, rotationMatrix(1,0), 0.0001); EXPECT_NEAR(0.8536, rotationMatrix(1,1), 0.0001); EXPECT_NEAR(-0.1464, rotationMatrix(1,2), 0.0001); EXPECT_NEAR(-0.7071, rotationMatrix(2,0), 0.0001); EXPECT_NEAR(0.5, rotationMatrix(2,1), 0.0001); EXPECT_NEAR(0.5, rotationMatrix(2,2), 0.0001); }