예제 #1
0
파일: Plane.cpp 프로젝트: luca-penasa/spc
Transform<float, 3, Affine, AutoAlign> Plane::get2DArbitraryRefSystem() const
{
    Eigen::Vector3f n = normal_.getUnitNormal();

    /// seek for a good unit axis to project on plane
    /// and then use it as X direction of the 2d local system
    size_t min_id;
    n.array().abs().minCoeff(&min_id);

    DLOG(INFO) << "min id is " << min_id;
    Vector3f proj_axis = Vector3f::Zero();
    proj_axis(min_id) = 1; // unity on that axis

    // project the selected axis on the plane
    Vector3f second_ax = projectVectorOnPlane(proj_axis);
    second_ax.normalize();

    Vector3f first_ax = n.cross(second_ax);

    first_ax.normalize();

    Transform<float, 3, Affine, AutoAlign> T;
//    T.matrix().fill(0);
    T.matrix().col(0).head(3) = first_ax;
    T.matrix().col(1).head(3) = second_ax;
    T.matrix().col(2).head(3) = n;
//    T.matrix()(3, 3) = 1;


    DLOG(INFO) << "Transform computed \n " << T.inverse().matrix() << "normal was " << n;

    DLOG(INFO) << "In fact T*n " <<T.inverse() *n;
    return T.inverse();
}
예제 #2
0
vec3_t intersectionOnPlane(vec3_t v, vec3_t A, vec3_t nA, vec3_t B, vec3_t nB)
{
  vec3_t u = B-A;
//   u.normalise();
  v.normalise();
  v = u.abs()*v;
  
  //cout<<"u="<<u<<" v="<<v<<endl;
  
  vec2_t p_A(0,0);
  vec2_t p_B(1,0);
  vec2_t p_nA = projectVectorOnPlane(nA,u,v);
  vec2_t p_nB = projectVectorOnPlane(nB,u,v);
  
  vec2_t p_tA = turnRight(p_nA);
  vec2_t p_tB = turnRight(p_nB);
  
  double k1, k2;
  vec2_t p_K;
  if(!intersection(k1, k2, p_A, p_tA, p_B, p_tB)) {
    //qDebug()<<"WARNING: No intersection found!!!";
    p_K = 0.5*(p_A + p_B);
  }
  else {
    p_K = p_A + k1*p_tA;
  }
  
  //cout<<"nA="<<nA<<endl;
  //cout<<"p_nA="<<p_nA<<endl;
  //cout<<"p_tA="<<p_tA<<endl;
  //cout<<"p_K="<<p_K<<endl;
  if(p_K[0]<0) p_K[0] = 0;
  if(p_K[0]>1) p_K[0] = 1;
  vec3_t K = A + p_K[0]*u + p_K[1]*v;
  //cout<<"K="<<K<<endl;
  return K;
}
예제 #3
0
		MStatus MG_dotProduct::compute(const MPlug& plug,MDataBlock& dataBlock)
	{
		MStatus returnStatus;
		if ((plug==dotProductA)||
			(plug==dotProductMax)||
			(plug==proj1on2)||
			(plug==proj2on1)||
			(plug==angleInBetweenAttr)||
			(plug==angleX)||
			(plug==angleY)||
			(plug==angleZ))
			/*get time */
		
		{
				
			//creating handles to the input values

			MDataHandle vector1DataH = dataBlock.inputValue(vector1);
			MFloatPoint vector1V = vector1DataH.asFloatVector();
			
			MDataHandle vector2DataH = dataBlock.inputValue(vector2);
			MFloatPoint vector2V = vector2DataH.asFloatVector();

			MDataHandle xAxisH = dataBlock.inputValue(projAxisX);
			MFloatPoint xAxisData = xAxisH.asFloatVector();

			MDataHandle yAxisH = dataBlock.inputValue(projAxisY);
			MFloatPoint yAxisData = yAxisH.asFloatVector();

			MDataHandle zAxisH = dataBlock.inputValue(projAxisZ);
			MFloatPoint zAxisData = zAxisH.asFloatVector();
			
			MDataHandle normData = dataBlock.inputValue(normalize);
			bool norm =normData.asBool();
			

			//Creating some neededs variables

			float dotResult; // variable that will hold the dot product result
			float maxValue; //variable that will hold the dot product max value 
			float distance1; // variable that will hold the vector 1 lenght 
			float distance2; //variable that will hold the  vector 2 lenght
			float angleDeg;  //variable that will hold the  angle inbetween the two vectors
			//float cosRad ;   //variable that will hold the cosine value in radiants 
				
			//Dot product math 

			float vec1Array[3] = {vector1V[0],vector1V[1],vector1V[2]};
			vector <float> vec1 = makeVector(vec1Array) ;

			float vec2Array[3] = {vector2V[0],vector2V[1],vector2V[2]};
			vector <float> vec2 = makeVector(vec2Array) ;

			dotResult = vecDotProduct(vec1,vec2);
			distance1 = vectorLength(vec1);
			distance2 = vectorLength(vec2);
			maxValue = distance1*distance2;

			
			if (norm == 1) 

			{
				if (maxValue ==0)
				{
					dotResult=0;
				}else{
					dotResult = dotResult/maxValue;
				}
			} 
  
			


				
				

			//Projection v2 on v1

			float projV2=0;  //variable that will hold the value projection of v2 projected on v1
			vector <float> v1Norm; // variable that will hold the normalized v1 vector
			vector<float> v2Vec; // variable that will hold the projected vector

			if (distance1 != 0) 
			{
 
				projV2 = projVector(vec2,vec1);
				

				v1Norm = normVector(vec1);


				v2Vec = scalarVector(v1Norm,projV2);
				
				

			}else{

				//initialize the vector as 0 0 0
				float zeroVec2[3]= {0,0,0};
				v2Vec=makeVector(zeroVec2);
			}


			//Projection v1 on v2

			float projV1=0; //variable that will hold the value projection of v1 projected on v2
			vector <float> v2Norm;// variable that will hold the normalized v2 vector
			vector <float> v1Vec;// variable that will hold the projected vector

			if (distance2 != 0) 
			{
				projV1 = projVector(vec1,vec2);


				v2Norm = normVector(vec2);
				v1Vec = scalarVector(v2Norm,projV1);
			}else{
				//initialize the vector as 0 0 0
				float zeroVec1[3]= {0,0,0};
				v1Vec=makeVector(zeroVec1);
			}

			
			//Angle in between 


			if ((distance2*distance1)!=0)
			{
			angleDeg=angleInbetweenVector(vec1,vec2);
			}else{
				angleDeg=0;

			}

			//Angle inbetween splitted into X,Y,Z world rotation 
			
			//float dotResultV1X;
			// splitting inbetween angle into X Y Z rotation



			//converting axis from node into vector class
			float xAxisArray[3] = {xAxisData[0],xAxisData[1],xAxisData[2]};
			vector<float> xAxisVec = makeVector(xAxisArray) ;
			
			float yAxisArray[3] = {yAxisData[0],yAxisData[1],yAxisData[2]};
			vector<float> yAxisVec = makeVector(yAxisArray) ;

			float zAxisArray[3] = {zAxisData[0],zAxisData[1],zAxisData[2]};
			vector<float> zAxisVec = makeVector(zAxisArray) ;


			float angleProjXYDeg=0 ;
			float angleProjYZDeg=0 ;
			float angleProjXZDeg=0 ;

			// angle Z
			

			vector<float> projectedV1;
			vector<float> projectedV2;

			projectedV1= projectVectorOnPlane(vec1,xAxisVec,yAxisVec);
			projectedV2= projectVectorOnPlane(vec2,xAxisVec,yAxisVec);
			angleProjXYDeg=angleInbetweenVector(projectedV1,projectedV2);



			// angle X
			

			projectedV1= projectVectorOnPlane(vec1,zAxisVec,yAxisVec);
			projectedV2= projectVectorOnPlane(vec2,zAxisVec,yAxisVec);
			angleProjYZDeg=angleInbetweenVector(projectedV1,projectedV2);


			// angle Y
			

			projectedV1= projectVectorOnPlane(vec1,zAxisVec,xAxisVec);
			projectedV2= projectVectorOnPlane(vec2,zAxisVec,xAxisVec);
			angleProjXZDeg=angleInbetweenVector(projectedV1,projectedV2);

















			//Setting output values

			MDataHandle output = dataBlock.outputValue(dotProductA);
			MDataHandle outputMax = dataBlock.outputValue(dotProductMax);
			MDataHandle projV1Output = dataBlock.outputValue(proj1on2);
			MDataHandle projV2Output = dataBlock.outputValue(proj2on1);
			MDataHandle angleInBetweenOutput = dataBlock.outputValue(angleInBetweenAttr);
			MDataHandle angleXout = dataBlock.outputValue(angleX);
			MDataHandle angleYout = dataBlock.outputValue(angleY);
			MDataHandle angleZout = dataBlock.outputValue(angleZ);




			output.set(dotResult);
			outputMax.set(maxValue);
			projV1Output.set(v1Vec[0],v1Vec[1],v1Vec[2]);
			projV2Output.set(v2Vec[0],v2Vec[1],v2Vec[2]);
			angleInBetweenOutput.set(angleDeg);
			angleXout.set(angleProjYZDeg);
			angleYout.set(angleProjXZDeg);
			angleZout.set(angleProjXYDeg);

			//SetClean tells maya attribute is update
			outputMax.setClean();
			output.setClean();
			projV1Output.setClean();
			projV2Output.setClean();
			angleInBetweenOutput.setClean();
			angleXout.setClean();
			angleYout.setClean();
			angleZout.setClean();
		}
		
		return MS::kSuccess;


		}