From 3d824dd8dc43d0bfda8c8ce7953d788ea248b029 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Thu, 15 Dec 2016 09:01:21 -0500 Subject: [PATCH] check vectors parallel, vec rotate arb axis, vec format improve --- src/Mod/TechDraw/App/DrawUtil.cpp | 24 +++++++++++++++++++----- src/Mod/TechDraw/App/DrawUtil.h | 8 +++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index df44a3da30..5eef409b63 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -270,7 +270,9 @@ std::string DrawUtil::formatVector(const Base::Vector3d& v) { std::string result; std::stringstream builder; + builder << std::fixed << std::setprecision(3) ; builder << " (" << v.x << "," << v.y << "," << v.z << ") "; +// builder << " (" << setw(6) << v.x << "," << setw(6) << v.y << "," << setw(6) << v.z << ") "; result = builder.str(); return result; } @@ -317,19 +319,31 @@ Base::Vector3d DrawUtil::toR3(const gp_Ax2 fromSystem, const Base::Vector3d from return toPoint; } -//! check if direction is parallel to stdZ -bool DrawUtil::checkZParallel(const Base::Vector3d direction) +//! check if two vectors are parallel +bool DrawUtil::checkParallel(const Base::Vector3d v1, Base::Vector3d v2) { bool result = false; - Base::Vector3d stdZ(0.0,0.0,1.0); - double dot = fabs(direction.Dot(stdZ)); - double mag = direction.Length() * 1; //stdZ.Length() == 1 + double dot = fabs(v1.Dot(v2)); + double mag = v1.Length() * v2.Length(); if (DrawUtil::fpCompare(dot,mag)) { result = true; } return result; } +//! rotate vector by angle radians around axis through org +Base::Vector3d DrawUtil::vecRotate(Base::Vector3d vec, + double angle, + Base::Vector3d axis, + Base::Vector3d org) +{ + Base::Vector3d result; + Base::Matrix4D xForm; + xForm.rotLine(org,axis,angle); + result = xForm * (vec); + return result; +} + //based on Function provided by Joe Dowsett, 2014 double DrawUtil::sensibleScale(double working_scale) { diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 25d4eb9abb..6abecf2fc9 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -37,6 +37,7 @@ #include #include +#include namespace TechDraw { @@ -60,7 +61,12 @@ class TechDrawExport DrawUtil { static std::string formatVector(const Base::Vector3d& v); static int vectorCompare(const Base::Vector3d& v1, const Base::Vector3d& v2); static Base::Vector3d toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint); - static bool checkZParallel(const Base::Vector3d direction); + static bool checkParallel(const Base::Vector3d v1, const Base::Vector3d v2); + //! rotate vector by angle radians around axis through org + static Base::Vector3d vecRotate(Base::Vector3d vec, + double angle, + Base::Vector3d axis, + Base::Vector3d org = Base::Vector3d(0.0,0.0,0.0)); //debugging routines