cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Transformation matrix

Ketan_Lalcheta
19-Tanzanite

Transformation matrix

Hello

I have a drawing of part file. Can I know transformation matrix for two of these ?

Thanks and Regards
Ketan
1 ACCEPTED SOLUTION

Accepted Solutions
FV
17-Peridot
17-Peridot
(To:Ketan_Lalcheta)

UgDrawingDimensions.c from pt_userguide directory has all answers you are looking for...UgDrawingDimensions.png

 

 

 

 


@Ketan_Lalcheta wrote:

I have a part which is having extrude feature. Extrude is displayed in drawing view.

 

I need to create dimension in drawing view. For that purpose, I am not asking user to select anything from view i.e. drawing.

 

In this scenario, what should be done to map co ordinate systems of drawing and part so that dimension is set in middle of dimension line. 

 

What all transformation is required for this scenario is what I need to know so that placement of text is proper.

I hope I cleared your confusion. Feel free to ask for clarification if it is still not clear.

 

Thanks and Regards

Ketan


 

View solution in original post

7 REPLIES 7

Any hint will be of great help guys.

Can you explane what you want? If be honest I'm dont understand Smiley Happy

I have a part which is having extrude feature. Extrude is displayed in drawing view.

 

I need to create dimension in drawing view. For that purpose, I am not asking user to select anything from view i.e. drawing.

 

In this scenario, what should be done to map co ordinate systems of drawing and part so that dimension is set in middle of dimension line. 

 

What all transformation is required for this scenario is what I need to know so that placement of text is proper.

I hope I cleared your confusion. Feel free to ask for clarification if it is still not clear.

 

Thanks and Regards

Ketan


@Ketan_Lalcheta wrote:

so that dimension is set in middle of dimension line.

 If you mean that dimension text must be placed in meddle of dimension line, i.e. in middle point of the edge in extrusion.

If so, then I think need to do:

1) Get coordinates middle point of the edge

2) ProViewMatrixGet()

3) Transforming Solid to Screen Coordinates

4) Calculate where the point is located on the drawing 

5) ProDrawingViewTransformGet

6) Transforming from Screen to Drawing Coordinates in a Drawing

 

Now you know a coordinates of the point in the drawing. Then compare this point with a point of dimension text.

 

Regarding your question here I found some old code I created and tested in Wildfire 4 releases (2009 -2010) It implement a task which more complex as  your problem but is related so you can see what kind of mathematical operation are used. Unfortunately, I could not provide the model because contains a customers sensitive data.

In the code are considered 2 cases
Case 1A required to create a dimension for Angle between 2 curvs in the part model. The 2 curvs are as input (the ids) and other input is the position of the dimension text/value on the drawing

Case 2B create a dimension between 2 curvs.  There is the attempt that the dimension should be created always in the inner angle side

===============

The code implements:

  • Some helpful utility function for mathematical operations

-the main function where the test function is called with arguments  tollkit_issue()

-the test function rayCreateDimTest() which implements the creation of the angle dimension and also used a flip argument for the second case

-ERR macro for simple debugging of the errors.

 

So I hope this code could provide some helpful information to you:

#include "ProToolkit.h"
#include "ProMenu.h"
#include "ProMenuBar.h"
#include "ProUtil.h"
#include "ProSolid.h"
#include <ProDtlentity.h>
#include <ProDrawing.h>
#include <ProDtlnote.h>
#include <pd_prototype.h>
#include <ProSelection.h>
#include <ProDimension.h>
//#include <ProAxis.h>
#include <ProModelitem.h>
#include <ProCurve.h>
#include <ProGraphic.h>
#include <pd_prototype.h>
#include  <math.h>
#define PI          3.14159265358979323846
#define EPSM6                 1.0e-6
/* Globals */
/* Globals */
ProError rayCreateDimTest (ProDrawing drawing,int Number_VIEW, int *ids,ProPoint3d Pos);

FILE *logfile;
ProError err_ray;
int find_id;
ProBoolean find;

/* Prototypes */
void print( char* name);
void toolkit_issue ();
ProError rayFindSymDefGet (ProDrawing drw, ProDtlsymdef *sym_def,wchar_t *selected);


/* macros */
#define ERR(api) { err_ray = api;if(err_ray != PRO_TK_NO_ERROR) {  \
	fprintf(logfile,"\n");\
	fprintf(logfile,#api " <> Error = %d  in File:<%s> Line <%d>)",\
	err_ray, __FILE__,__LINE__); fflush(logfile);return;}}

/*************************************************************************/

int tk_issue (ProAppData arg_1, int arg_2)
{
	toolkit_issue ();
	return(0);
}


int user_initialize()
{
	ProError err;
	uiCmdCmdId   cmd_id;

	logfile = fopen("log.txt", "w");
	fprintf(logfile, "Log started.");
	fprintf(logfile, "\n=============\n");
	fflush(logfile);

	err=ProCmdActionAdd("Toolkit_Issue", (uiCmdCmdActFn) tk_issue, uiProe2ndImmediate,
		NULL, PRO_B_TRUE, PRO_B_TRUE, &cmd_id);
	err=ProMenubarMenuAdd("Toolkit Menu", "Toolkit Menu", "Help", PRO_B_TRUE, L"message.txt");
	err=ProMenubarmenuPushbuttonAdd("Toolkit Menu", "Toolkit Button", "Toolkit Button", "Toolkit Button",
		NULL, PRO_B_TRUE, cmd_id, L"message.txt");

	return (0);
}


void user_terminate()
{
	fprintf(logfile, "\n\n================================================\n");
	fprintf(logfile,   "Pro/TOOLKIT application terminated successfully.");
	fprintf(logfile, "\n================================================\n");

	fflush(logfile);
	fclose(logfile);
}


void print( char* name)
{
	fprintf(logfile, "\n%s", name);
	fflush(logfile);
}
void wprint(ProName wname )
{
	char name[256];
	print(ProWstringToString(name,wname));
}

double ProUtilVectorDot123(
    double a[3],
    double b[3])
{
    double dot;
    dot = a[2] * b[2] + a[1] * b[1] + a[0] * b[0];
    return(dot);
}

double ProUtilVectorLength123(
    double v[3])
{
    return(sqrt(v[0] * v[0] +
		v[1] * v[1] +
		v[2] * v[2]));
}
/*====================================================================*\
    FUNCTION :	ProUtilPlaneLineInter()
    PURPOSE  :	Intersection between a plane and a line
\*====================================================================*/
double *ProUtilPlaneLineX123(
    double plane_point[3],	/* IN - point on the plane	*/
    double plane_normal[3],	/* IN - normal to the plane	*/
    double line_point[3],	/* IN - point on the line	*/
    double line_dir[3],		/* IN - direction of the line	*/
    double x_point[3])		/* OUT - intersection point	*/
{
    double proj, vector[3], dist;

    proj = ProUtilVectorDot(plane_normal, line_dir);

/*--------------------------------------------------------------------*\
    If the line is parallel to the plane, return NULL
\*--------------------------------------------------------------------*/
    if(fabs(proj) < EPSM6)
	return(NULL);

    ProUtilVectorDiff(plane_point, line_point, vector);
    dist = ProUtilVectorDot(vector, plane_normal)/proj;
    ProUtilVectorsLincom(1.0, line_point, dist, line_dir, x_point);
    return(x_point);
}

void printPnt(char *name,double point[3])
{int i=0;
fprintf(logfile, "\nPrint Point <%s>  ",name);fflush(logfile);
fprintf(logfile, "\n==============================");fflush(logfile);
for(i =0;i<3;i++){
	fprintf(logfile, "\nPNT[%d] =%f ",i,point[i]);fflush(logfile);}
fprintf(logfile, "\n==============================\n");fflush(logfile);
	return;}

	
	/***********
considered 2 cases
	Case 1A  required to create a dimension for Angle between 2 curvs in the part model. The 2 curvs are as input (the ids) and other input is the  position of the dimension text/value on the drawing
	
	Case 2B create a dimension between 2 curvs. the dimension should be created  always in the inner angle side
/******************************************/
void toolkit_issue ()
{
	ProError err,status;
	ProMdlType mtype;
	ProName wname;

		ProDrawing drawing;
		ProSolid Solid;
		ProView *views  = NULL;
	    ProName name;
		ProCharLine  view_name;
		ProCurve  curvs[2];
		int i,ii;
//application cases
		int Number_VIEW =0; /*  Case1A */
		int ids[4]={36322,62092};  /*call Case1A*/
		//int ids[4]={62092,36322};  /*call Case1A*/
         ProPoint3d Pos = { 460.0, 445.0,0.0};/*call  Case1A*/

        //=================================================

        int Number_VIEW1 =0; /*call Case 2B */
		int ids1[4]={13598,13733};/*call Case 2B */
		//int ids1[4]={13733,13598};/*call Case 2B */
	    ProPoint3d Pos1 = { 150.0, 630.0,0.0};/*call  Case1A */
	    //========================================================

	    int Number_VIEW2 =1; /*call Case 2B B*/
	    int ids2[4]={13598,13733};/*call Case 2B */
	   // int ids2[4]={13733,13598};/*call Case 2B */
	    ProPoint3d Pos2 = { 860.0, 630.0,0.0};/*call  Case1A */

	     //=====================================================================

		ProGeomitem curv_geomitem;
		ProSelection curv_selection ;
		ProGeomitemdata *curv_data;
	ProMatrix trf;
    ProSelection *attachments;
	ProDimSense *senses;
    	ProPoint3d pnts1[2],pnts2[2],tmpPnt,xPnt;
    	ProVector normscreenPnt={0.0,0.0,1.0};
		ProDimension dimension;
			double Winkel;
		ProVector vecs[2],trfvecs,normVec,xVec[2],xPos;
		double dotProd;
		double vecWinkel,vecWinkel1,vecWinkel2;
        ProPoint3d trfPntX,trfPnt1,trfPnt2;
/************************************************************************/

	ERR(ProMdlCurrentGet(&drawing))
	ERR(ProMdlTypeGet(drawing,&mtype))
	if( mtype == PRO_DRAWING )
	{
	/*call Case1A*/
	rayCreateDimTest (drawing,Number_VIEW, ids,Pos);
	/*call Case 2B A*/
	rayCreateDimTest (drawing,Number_VIEW1, ids1,Pos1);
	rayCreateDimTest (drawing,Number_VIEW2, ids2,Pos2);
	} /*drawing */
	else
	print("The current model is not a drawing");



ProInfoWindowDisplay(L"log.txt", NULL, NULL);
return;
}

/*************************************************************************/
/********   ISSUE RELATED Programming Code  bellow            ************/
/*************************************************************************/

ProError rayCreateDimTest (ProDrawing drawing,int Number_VIEW, int *ids,ProPoint3d Pos)
{
	ProError err,status;
	ProMdlType mtype;
	ProName wname;


		ProSolid Solid;
		ProView *views  = NULL;
	    ProName name;
		ProCharLine  view_name;
		ProCurve  curvs[2];
		int i,ii;
//application cases

        ProBoolean should_flip 	= PRO_B_FALSE;  /*call Case 2B  */
        //=================================================
		ProGeomitem curv_geomitem;
		ProSelection curv_selection ;
		ProGeomitemdata *curv_data;
	ProMatrix trf;
    ProSelection *attachments,*invert_attachments;
	ProDimSense *senses;
    	ProPoint3d pnts1[2],pnts2[2],tmpPnt,xPnt;
    	ProVector normscreenPnt={0.0,0.0,1.0};
		ProDimension dimension;
			double Winkel;
		ProVector vecs[2],trf_vecs[2],trfvecs,normVec,xVec[2],xPos;
		double dotProd;
		double vecWinkel,vecWinkel1,vecWinkel2;
        ProPoint3d trfPntX,trfPnt1,trfPnt2;
        ProBoolean INNEN_WINKEL;
        int invert_ids[2];
        double dot_vecs,dot_trfvecs,dot1,dot2;
        ProVector cross_vecs, cross_trfvecs;

/************************************************************************/

	ERR(ProMdlCurrentGet(&drawing))
	ERR(ProMdlTypeGet(drawing,&mtype))
	if( mtype == PRO_DRAWING )
	{

	//	View Handle
		ERR(ProDrawingViewsCollect(drawing, &views))
		ERR(ProDrawingViewNameGet (drawing, views[Number_VIEW], name))
	    ProWstringToString (view_name, name);
	    fprintf(logfile, "\nView[0] Name =%S",name);fflush(logfile);
	//solid of the view
	   ERR(ProDrawingViewSolidGet(drawing,views[Number_VIEW],&Solid))
	 //	Transformations-Matrix
	   ERR(ProDrawingViewTransformGet(drawing, views[Number_VIEW], PRO_B_TRUE, trf))
	   //transform from model to screen
     for(i=1;i>-1;i--) invert_ids[i]=ids[1-i];

      ERR(ProArrayAlloc(2, sizeof(ProDimSense),  1, (ProArray*)&senses))
	  ERR(ProArrayAlloc(2, sizeof(ProSelection), 1, (ProArray*)&attachments))
	  ERR(ProArrayAlloc(2, sizeof(ProSelection), 1, (ProArray*)&invert_attachments))

       for (i=0;i<2;i++)
       {
	   ERR( ProCurveInit(Solid, ids[i], &curvs[i]))
       ERR(ProCurveToGeomitem(Solid, curvs[i], &curv_geomitem))
       ERR(ProCurveDataGet(curvs[i], &curv_data))
       //ray Annahme without checking line type curv
       for(ii=0;ii<3;ii++){
		   vecs[i][ii]=   curv_data->data.p_curve_data->line. end2[ii]
		                - curv_data->data.p_curve_data->line. end1[ii];
		fprintf(logfile,"\nvecs[%d][%d]= %f  ",i,ii,vecs[i][ii]);fflush(logfile);
		pnts1[i][ii]=curv_data->data.p_curve_data->line. end1[ii];
		pnts2[i][ii]=curv_data->data.p_curve_data->line. end2[ii];
		                   }
        ProUtilVectorNormalize(vecs[i], vecs[i]);
        ProVectorTrfEval(vecs[i], trf, trf_vecs[i]);
	   ERR(ProSelectionAlloc(NULL, &curv_geomitem, &curv_selection))
	   ERR(ProSelectionViewSet(views[Number_VIEW], &curv_selection))
       ERR(ProSelectionHighlight(curv_selection,PRO_COLOR_SHEETMETAL))
       ERR(ProSelectionAlloc(NULL, &curv_geomitem, &attachments[i]))
       ERR(ProSelectionAlloc(NULL, &curv_geomitem, &invert_attachments[1-i]))
	   ERR(ProSelectionViewSet(views[Number_VIEW], &attachments[i]))
	   ERR(ProSelectionViewSet(views[Number_VIEW], &invert_attachments[1-i]))


//	Senses
	senses[i].type = PRO_DIM_SNS_TYP_ANGLE;
	senses[i].angle_sense.is_first = (i==0)?PRO_B_TRUE:PRO_B_FALSE;
	senses[i].angle_sense.should_flip =  PRO_B_FALSE;
	senses[i].orient_hint = PRO_DIM_ORNT_NONE;

      }

ProUtilVectorCross(vecs[0],vecs[1],cross_vecs);
ProUtilVectorCross(trf_vecs[0],trf_vecs[1],cross_trfvecs);
dot_vecs=ProUtilVectorDot123(cross_vecs,cross_trfvecs);



{

   vecWinkel= acos(ProUtilVectorDot123(vecs[0],vecs[1])/
                       (ProUtilVectorLength123(vecs[0])*ProUtilVectorLength123(vecs[1]) ))
                        /PI*180.0;
}



	for(ii=0;ii<10;ii=ii+2)
	ProGraphicsCircleDraw(Pos, ii);
    ProUtilVectorCross(vecs[0],normscreenPnt,normVec);
    ProUtilVectorNormalize(normVec, normVec);
	ProUtilPlaneLineX(pnts1[0],normVec, pnts1[1],vecs[1], &xPnt);

    ERR(ProPntTrfEval(xPnt, trf, trfPntX))
    ERR(ProPntTrfEval(pnts2[0], trf, trfPnt1))
    ERR(ProPntTrfEval(pnts2[1], trf, trfPnt2))

    for(ii=0;ii<5;ii=ii+1)
	ProGraphicsCircleDraw(trfPntX, ii);

	for(ii=0;ii<3;ii++)
	{ xVec[0][ii]	=	trfPnt1[ii]	-trfPntX[ii];
	  xVec[1][ii]	=	trfPnt2[ii]	-trfPntX[ii];
	  xPos[ii]		=	Pos[ii]		-trfPntX[ii];
	}

    for(i=0;i<2;i++) ProUtilVectorNormalize(xVec[i], xVec[i]);

	ProUtilVectorNormalize(xPos, xPos);



	ERR(ProVectorTrfEval(xPos, trf, trfvecs))

	vecWinkel1= acos(ProUtilVectorDot123(trfvecs,xVec[0])/
	                       (ProUtilVectorLength123(trfvecs)*ProUtilVectorLength123(xVec[0]) ))
                        /PI*180.0;

    vecWinkel2= acos(ProUtilVectorDot123(xVec[1],trfvecs)/
		                       (ProUtilVectorLength123(trfvecs)*ProUtilVectorLength123(xVec[1]) ))
                        /PI*180.0;



    INNEN_WINKEL= (vecWinkel>=vecWinkel1+vecWinkel2-EPSM6 )?PRO_B_TRUE:PRO_B_FALSE;
     dot1=ProUtilVectorDot123(xVec[0],vecs[0]);
	 dot2=ProUtilVectorDot123(xVec[1],vecs[1]);

    for(i=0;i<2;i++)
       {
  			if ( (dot_vecs>0) && ((dot1 <0) &&(dot2 < 0)))
  				senses[i].angle_sense.should_flip =PRO_B_TRUE;}


   if((INNEN_WINKEL)  )
     {  ERR(ProDrawingDimCreate(drawing, attachments, senses, Pos,
				PRO_B_FALSE, &dimension)) }
	else
	{ ERR(ProDrawingDimCreate(drawing, invert_attachments, senses, Pos,
				PRO_B_FALSE, &dimension))}

	ERR(ProDimensionNomvalueGet(&dimension , &Winkel))
	ERR(ProDimensionShow(&dimension, views[Number_VIEW], drawing, NULL))

/*****************************/

	} /*drawing */



return(PRO_TK_NO_ERROR);
}


===============

Thanks a lot. Will share test result once I will check this.

FV
17-Peridot
17-Peridot
(To:Ketan_Lalcheta)

UgDrawingDimensions.c from pt_userguide directory has all answers you are looking for...UgDrawingDimensions.png

 

 

 

 


@Ketan_Lalcheta wrote:

I have a part which is having extrude feature. Extrude is displayed in drawing view.

 

I need to create dimension in drawing view. For that purpose, I am not asking user to select anything from view i.e. drawing.

 

In this scenario, what should be done to map co ordinate systems of drawing and part so that dimension is set in middle of dimension line. 

 

What all transformation is required for this scenario is what I need to know so that placement of text is proper.

I hope I cleared your confusion. Feel free to ask for clarification if it is still not clear.

 

Thanks and Regards

Ketan


 

Top Tags