Visualizzazione dei risultati da 1 a 8 su 8
  1. #1

    [C++/C] Problema nel passaggio di valori

    Salve a tutti!

    è la prima volta che scrivo sul forum, quindi colgo l'occasione per ringraziare tutti voi del grande aiuto che date a tutti i programmatori in erba con i vostri post!

    Questa volta, però, devo chiedere io aiuto, in quanto non riesco a capire bene dov'è l'errore in questo mio sorgente. In compilazione non ricevo nessun errore, ma in esecuzione i risultati
    sono tutti = 0.

    C'è qualcuno che può aiutarmi?

    codice:
    //Headers
    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    
    #define UNDEFINED	0
    #define DEF_X		1
    #define DEF_Y		2
    
    #define VERSION 	"v0.2.1\0"
    using namespace std;
    
    //Global Var
    double GL_angle=0;
    double GL_area=0;
    int GL_Definition_switch=UNDEFINED;
    int GL_Objects=1;
    
    //Global Vectors
    double* GL_cg;
    double* GL_inertial_moment;
    double* GL_central_inertial_moment;
    double* GL_radius_ellipse;
    
    //Declarations
    double area(); 
    
    int definition_central_rotation(double* _inertial_moment);
    
    double* cg(double _area); 
    double* ellipse_radius(double* _central_inertial_moment, double _area);
    double rotation_angle(double* _inertial_moment);
    double* central_inertial_moment(double* _inertial_moment);
    double* inertial_moment(double* __cg);
    
    //Class Declarations
    class CLASS_rectangle
    {	
    	private:
    		double* PR_vertex;
    		double PR_height;
    		double PR_base;
    		
    	public:
    		double* PB_relative_inertial_moment;
    		double* PB_relative_cg;
    		double PB_area;
    		
    		CLASS_rectangle(const CLASS_rectangle&);
    		void assign(double _vertex_x, double _vertex_y, double _base, double _height)
    		{
    			PR_vertex=(double*)malloc(2*sizeof(double));
    			PR_vertex[0]=_vertex_x;
    			PR_vertex[1]=_vertex_y;
    			
    			PR_height=_height;
    			PR_base=_base;
    			PB_area=_base*_height;
    			
    			PB_relative_cg=(double*)malloc(2*sizeof(double));
    			PB_relative_cg[0]=PR_vertex[0]+_base/2;
    			PB_relative_cg[1]=PR_vertex[1]+_height/2;
    			
    			PB_relative_inertial_moment=(double*)malloc(3*sizeof(double));
    			PB_relative_inertial_moment[0]=pow(_height, 3.0)*_base*(1.0/12.0);
    			PB_relative_inertial_moment[1]=pow(_base, 3.0)*_height*(1.0/12.0);
    			PB_relative_inertial_moment[2]=0;		
    		};
    		double* absolute_inertial_moment(double* _cg)
    		{
    			double* V_absolute_inertial_moment;
    			V_absolute_inertial_moment=(double*)malloc(3*sizeof(double));
    			
    			V_absolute_inertial_moment[0]=(PB_relative_inertial_moment[0]+pow((PB_relative_cg[0]-_cg[0]),2.0)*PB_area);
    			V_absolute_inertial_moment[1]=(PB_relative_inertial_moment[1]+pow((PB_relative_cg[1]-_cg[1]),2.0)*PB_area);
    			V_absolute_inertial_moment[2]=(PB_relative_inertial_moment[2]+(PB_relative_cg[0]-_cg[0])*(PB_relative_cg[1]-_cg[1])*PB_area);
    		
    			return V_absolute_inertial_moment;
    		};
    		~CLASS_rectangle() 
    		{
    			free((void*)PB_relative_inertial_moment);
    			free((void*)PR_vertex);
    			free((void*)PB_relative_cg);
    		};
    };
    
    //Objects declarations
    CLASS_rectangle* rectangle;
    
    //Implementation
    
    double area()
    {
    	double temp_area=0.0;
    	int Counter=0;
    	
    	while ( Counter<=(GL_Objects-1) )
    	{
    		temp_area=temp_area+rectangle[Counter].PB_area;
    		Counter+=1;
    	}
    	
    	return temp_area;
    };
    
    int definition_central_rotation(double* _inertial_moment)
    {
    	if (_inertial_moment[0]>=_inertial_moment[1])
    		return DEF_X;
    	else
    		return DEF_Y;
    };
    
    double* cg(double _area)
    {
    	double* V_cg;
    	V_cg=(double*)malloc(2*sizeof(double));
    	int Counter=0;
    	
    	while ( Counter <= (GL_Objects-1) )
    	{
    		V_cg[0]=V_cg[0]+(rectangle[Counter].PB_relative_cg[0]*rectangle[Counter].PB_area);
    		V_cg[1]=V_cg[1]+(rectangle[Counter].PB_relative_cg[1]*rectangle[Counter].PB_area);
    		Counter+=1;
    	};
    	
    	V_cg[0]=V_cg[0]/_area;
    	V_cg[1]=V_cg[1]/_area;
    	
    	return V_cg;
    };
    
    double* ellipse_radius(double* _central_inertial_moment, double _area)
    {
    	double* V_ellipse_radius;
    	V_ellipse_radius=(double*)malloc(2*sizeof(double));
    	
    	V_ellipse_radius[0]=sqrt(_central_inertial_moment[0]/_area);
    	V_ellipse_radius[1]=sqrt(_central_inertial_moment[1]/_area);
    	
    	return V_ellipse_radius;
    };
    
    double rotation_angle(double* _inertial_moment)
    {
    	if ( inertial_moment[2] != 0 ) 
    		return (double)(0.5*atan(((-2)*_inertial_moment[2])/(_inertial_moment[0]-_inertial_moment[1])));
    	else 
    		return 0.0;
    };
    
    double* central_inertial_moment(double* _inertial_moment)
    {
    	double* V_iner_cent_temp;
    	V_iner_cent_temp=(double*)malloc(2*sizeof(double));
    	
    	if ( _inertial_moment[2] != 0 )
    	{
    		if ( _inertial_moment[0]>=_inertial_moment[1] )
    		{
    			V_iner_cent_temp[0]=_inertial_moment[0];
    			V_iner_cent_temp[1]=_inertial_moment[1];
    			
    			return V_iner_cent_temp;
    		}
    		else
    		{
    			V_iner_cent_temp[1]=_inertial_moment[0];
    			V_iner_cent_temp[0]=_inertial_moment[1];
    			
    			return V_iner_cent_temp;
    		}
    	}
    	else
    	{ 
    		
    		V_iner_cent_temp[1]=(0.5*(_inertial_moment[0]+_inertial_moment[1])+sqrt(pow((0.5*fabs((_inertial_moment[0]-_inertial_moment[1]))),2.0)+pow(_inertial_moment[2],2.0)));
    		V_iner_cent_temp[2]=(0.5*(_inertial_moment[0]+_inertial_moment[1])-sqrt(pow((0.5*fabs((_inertial_moment[0]-_inertial_moment[1]))),2.0)+pow(_inertial_moment[2],2.0)));
    		
    		return V_iner_cent_temp;
    	}
    };
    
    double* inertial_moment(double* __cg)
    {
    	double* V_inertial_moment;
    	V_inertial_moment=(double*)malloc(3*sizeof(double));
    	int Counter=0;
    	
    	while ( Counter <= (GL_Objects-1) )
    	{
    		double* V_temp_im;
    		V_temp_im=(double*)malloc(3*sizeof(double));
    		V_temp_im=rectangle[Counter].absolute_inertial_moment(__cg);
    		
    		int i=0;
    		
    		for (i=0; i<3; i++)
    			V_inertial_moment[i]=V_inertial_moment[i]+V_temp_im[i];
    		
    		free((void*)V_temp_im);
    		Counter+=1;
    	}
    	
    	return V_inertial_moment;
    }
    
    //Other implementations
    
    
    //### MAIN ###
    int main()
    {
    	printf("Nirvana1289 2010\n----------------------------------------\nGEOMETRIA DELLE AREE %s \n----------------------------------------\n\n", VERSION);
    	
    	//Obtain datas
    	int Counter=0;
    	
    	do
    	{
    		printf("Inserire il numero di rettangoli che compongono la figura: "); scanf("%d", &GL_Objects);printf("\n");
    	}
    	while ( GL_Objects<=0 );
    	
    	//Creating Objects
    	rectangle=(CLASS_rectangle*)malloc(GL_Objects*sizeof(CLASS_rectangle));
    	
    	while ( Counter <= (GL_Objects-1) )
    	{
    		double temp_vertex_X, temp_vertex_Y, temp_base, temp_height;
    		temp_vertex_X=temp_vertex_Y=temp_base=temp_height=0.0;
    		
    		printf("Rettangolo %d:\n", (Counter+1));
    		printf("Inserire posizione vertice inferiore sinistro (x,y): "); scanf("%f,%f",&temp_vertex_X, &temp_vertex_Y); 
    		printf("Inserire base: "); scanf("%f", &temp_base); 
    		printf("Inserire altezza: "); scanf("%f", &temp_height); 
    		
    		rectangle[Counter].assign(temp_vertex_X, temp_vertex_Y, temp_base, temp_height);
    			
    		Counter+=1;
    	}
    	
    	//Calculate
    	printf("\nCalcolo...\n");
    	
    	printf("Espansione vettori...\n");
    	GL_cg=(double*)malloc(2*sizeof(double));
    	GL_inertial_moment=(double*)malloc(3*sizeof(double));
    	GL_central_inertial_moment=(double*)malloc(2*sizeof(double));
    	GL_radius_ellipse=(double*)malloc(2*sizeof(double));
    	
    	printf("Definizione risultati...\n");
    	GL_area=area();
    	GL_cg=cg(GL_area);
    	GL_inertial_moment=inertial_moment(GL_cg);
    	GL_angle=rotation_angle(GL_inertial_moment);
    	GL_Definition_switch=definition_central_rotation(GL_inertial_moment);
    	GL_central_inertial_moment=central_inertial_moment(GL_inertial_moment);
    	GL_radius_ellipse=ellipse_radius(GL_central_inertial_moment, GL_area);
    	
    	printf("... completato!\n");
    	
    	//Printing results
    	printf("\n--- RISULTATI ---\n");
    	
    	printf("\n1 - BARICENTRO\n\n");
    	printf("Oggetto     \t       Area\t    Baricentro (relativo)\n\n");
    	Counter=0;
    	while ( Counter<=(GL_Objects-1) )
    	{
    		printf("Rettangolo %d\t%7.3f m^2\t%7.3f m\t%7.3f m\n", (Counter+1), rectangle[Counter].PB_area, rectangle[Counter].PB_relative_cg[0], rectangle[Counter].PB_relative_cg[1]);
    		Counter+=1;
    	}
    	printf("\nSistema        \t%7.3f m^2\t%7.3f m\t%7.3f m\n", GL_area, GL_cg[0], GL_cg[1]);
    	
    	printf("\n2 - MOMENTO DI INERZIA (relativo al G dei rettangoli)\n\n");
    	printf("Oggetto     \t   MomIn x'\t   MomIn y'\t MomIn x'y'\n\n");
    	Counter=0;
    	while ( Counter<=(GL_Objects-1) )
    	{
    		printf("Rettangolo %d\t%7.3f m^4\t%7.3f m^4\t%7.3f m^4\n", (Counter+1), rectangle[Counter].PB_relative_inertial_moment[0], rectangle[Counter].PB_relative_inertial_moment[1], rectangle[Counter].PB_relative_inertial_moment[2]);
    		Counter+=1;
    	}
    		
    	printf("\n3 - MOMENTO DI INERZIA (relativo al G del sistema)\n\n");
    	printf("Oggetto     \t   MomIn X\t    MomIn Y\t   MomIn XY\n\n");
    	printf("Sistema        \t%7.3f m^4\t%7.3f m^4\t%7.3f m^4\n", GL_inertial_moment[0], GL_inertial_moment[1], GL_inertial_moment[2]);
    	
    	printf("\n4 - MOMENTI CENTRALI DI INERZIA\n\n");
    	switch (GL_Definition_switch)
    	{
    		case UNDEFINED:
    			printf("ERRORE :(\n");
    		break;
    		case DEF_X:
    			printf("[PSI] -> rotazione di X\n[ETA] -> rotazione di Y\n");
    		break;
    		case DEF_Y:
    			printf("[PSI] -> rotazione di Y\n[ETA] -> rotazione di X\n");
    		break;
    	}
    	printf("\nAngolo di rotazione: %7.3f rad\n", GL_angle);
    	printf("\nMomenti centrali di inerzia:\nMomIn[PSI] = %7.3f m^4\nMomIn[ETA] = %7.3f m^4\n", GL_central_inertial_moment[0], GL_central_inertial_moment[1]);
    	
    	printf("\n5 - RAGGI ELLISSE DI INERZIA\n\n");
    	printf("[RHO][PSI] = %7.3f m\n[RHO][ETA] = %7.3f m\n",GL_radius_ellipse[0],GL_radius_ellipse[1]);
    	
    	printf("\n...DONE... \n");
    	return 0;
    };

  2. #2

    Re: [C++/C] Problema nel passaggio di valori

    Originariamente inviato da nirvana1289
    In compilazione non ricevo nessun errore, ma
    codice:
    //Headers
    ...
    double rotation_angle(double* _inertial_moment)
    {
    	if ( inertial_moment[2] != 0 ) 
    		return (double)(0.5*atan(((-2)*_inertial_moment[2])/(_inertial_moment[0]-_inertial_moment[1])));
    	else 
    		return 0.0;
    };
    cambia compilatore!
    codice:
    $ g++ main.cpp
    main.cpp: In function ‘double rotation_angle(double*)’:
    main.cpp: 147: error: pointer to a function used in arithmetic
    Probabilmente avresti voluto scrivere:
    codice:
    _inertial_moment[2]
    ma avendo scritto:
    codice:
    inertial_moment[2]
    ed essendo presente la funzione:
    codice:
    double* inertial_moment(double* __cg)
    accedi al terzo elemento di un puntatore a funzione!

  3. #3
    Verissimo! avevo fatto un errore, e infatti la tua modifica mi elimina il w del compilatore.
    Ma resta comunque il fatto che il programma mi produce come risultato tutti valori uguali a zero!

    Grazie ancora! ciao ciao

  4. #4
    Originariamente inviato da nirvana1289
    Verissimo! avevo fatto un errore, e infatti la tua modifica mi elimina il w del compilatore.
    Ma resta comunque il fatto che il programma mi produce come risultato tutti valori uguali a zero!

    Grazie ancora! ciao ciao
    incomincia ad eliminare anche tutti gli altri warning no? ;-)

  5. #5
    xk a te dà altri warning in compiling? a me dava solo quello, ora genera l'out senza messaggi.

    Il problema non è nel codice ma è o nel passaggio di dati o nella creazione di quella sorta di vettore di oggetti, che poi non si becca i dati durante l'inserimento da parte dell'utente... ma non ne vengo fuori... cioè non riesco a capire dove sbaglio, quindi probabilmente è un errore concettuale mio.

    grazie ancora per il vostro tempo.

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2009
    Messaggi
    225
    ci sono ancora alcuni warning
    codice:
    sergio@casa:~/tmp$ g++ prova.cpp
    prova.cpp: In function ‘int main()’:
    prova.cpp:235: warning: format ‘%f’ expects type ‘float*’, but argument 2 has type ‘double*’
    prova.cpp:235: warning: format ‘%f’ expects type ‘float*’, but argument 3 has type ‘double*’
    prova.cpp:236: warning: format ‘%f’ expects type ‘float*’, but argument 2 has type ‘double*’
    prova.cpp:237: warning: format ‘%f’ expects type ‘float*’, but argument 2 has type ‘double*’
    sergio@casa:~/tmp$
    prova ad eliminarli, per esempio facendo

    codice:
    float temp_vertex_X, temp_vertex_Y, temp_base, temp_height;
    		temp_vertex_X=temp_vertex_Y=temp_base=temp_height=0.0;

  7. #7
    Ottimo. Hai trovato l'errore.

    In realtà la soluzione era modificare l'acquisizione dei dati negli scanf, da %f a %lf. Ora devo risolvere i problemi di eccessiva verbosità dell'out del mio programma!! lol

    A dir la verità, non penso ci sarei mai arrivato perché il mio compilatore non mi dava nessun warning!! :master:

    ATTENZIONE----
    Modifico il programma nel mio vecchio post alla versione attuale! Viva l'open source!

  8. #8
    Siccome non mi lascia fare più modifiche a voi il sorgente corretto:

    codice:
    /*
    Programma di geometria delle aree. v0.2.3 Nirvana1289 2010.
    -----------------------------------------------------------
    */
    
    
    //Headers
    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    
    #define UNDEFINED	0
    #define DEF_X		1
    #define DEF_Y		2
    
    #define VERSION 	"v0.2.3\0"
    using namespace std;
    
    //Global Var
    double GL_angle=0;
    double GL_area=0;
    int GL_Definition_switch=UNDEFINED;
    int GL_Objects=1;
    
    //Global Vectors
    double* GL_cg;
    double* GL_inertial_moment;
    double* GL_central_inertial_moment;
    double* GL_radius_ellipse;
    
    //Declarations
    double area(); 
    
    int definition_central_rotation(double* _inertial_moment);
    
    double* cg(double _area); 
    double* ellipse_radius(double* _central_inertial_moment, double _area);
    double rotation_angle(double* _inertial_moment);
    double* central_inertial_moment(double* _inertial_moment);
    double* inertial_moment(double* __cg);
    
    //Class Declarations
    class CLASS_rectangle
    {	
    	private:
    		double* PR_vertex;
    		double PR_height;
    		double PR_base;
    		
    	public:
    		double* PB_relative_inertial_moment;
    		double* PB_relative_cg;
    		double PB_area;
    		
    		CLASS_rectangle(const CLASS_rectangle&);
    		void assign(double _vertex_x, double _vertex_y, double _base, double _height)
    		{
    			PR_vertex=(double*)malloc(2*sizeof(double));
    			PR_vertex[0]=_vertex_x;
    			PR_vertex[1]=_vertex_y;
    			
    			PR_height=_height;
    			PR_base=_base;
    			PB_area=_base*_height;
    			
    			PB_relative_cg=(double*)malloc(2*sizeof(double));
    			PB_relative_cg[0]=PR_vertex[0]+_base/2;
    			PB_relative_cg[1]=PR_vertex[1]+_height/2;
    			
    			PB_relative_inertial_moment=(double*)malloc(3*sizeof(double));
    			PB_relative_inertial_moment[0]=pow(_height, 3.0)*_base*(1.0/12.0);
    			PB_relative_inertial_moment[1]=pow(_base, 3.0)*_height*(1.0/12.0);
    			PB_relative_inertial_moment[2]=0;		
    		};
    		double* absolute_inertial_moment(double* _cg)
    		{
    			double* V_absolute_inertial_moment;
    			V_absolute_inertial_moment=(double*)malloc(3*sizeof(double));
    			
    			V_absolute_inertial_moment[0]=(PB_relative_inertial_moment[0]+pow((PB_relative_cg[0]-_cg[0]),2.0)*PB_area);
    			V_absolute_inertial_moment[1]=(PB_relative_inertial_moment[1]+pow((PB_relative_cg[1]-_cg[1]),2.0)*PB_area);
    			V_absolute_inertial_moment[2]=(PB_relative_inertial_moment[2]+(PB_relative_cg[0]-_cg[0])*(PB_relative_cg[1]-_cg[1])*PB_area);
    		
    			return V_absolute_inertial_moment;
    		};
    		~CLASS_rectangle() 
    		{
    			free((void*)PB_relative_inertial_moment);
    			free((void*)PR_vertex);
    			free((void*)PB_relative_cg);
    		};
    };
    
    //Objects declarations
    CLASS_rectangle* rectangle;
    
    //Implementation
    
    double area()
    {
    	double temp_area=0.0;
    	int Counter=0;
    	
    	while ( Counter<=(GL_Objects-1) )
    	{
    		temp_area=temp_area+rectangle[Counter].PB_area;
    		Counter+=1;
    	}
    	
    	return temp_area;
    };
    
    int definition_central_rotation(double* _inertial_moment)
    {
    	if (_inertial_moment[0]>=_inertial_moment[1])
    		return DEF_X;
    	else
    		return DEF_Y;
    };
    
    double* cg(double _area)
    {
    	double* V_cg;
    	V_cg=(double*)malloc(2*sizeof(double));
    	int Counter=0;
    	
    	while ( Counter <= (GL_Objects-1) )
    	{
    		V_cg[0]=V_cg[0]+(rectangle[Counter].PB_relative_cg[0]*rectangle[Counter].PB_area);
    		V_cg[1]=V_cg[1]+(rectangle[Counter].PB_relative_cg[1]*rectangle[Counter].PB_area);
    		Counter+=1;
    	};
    	
    	V_cg[0]=V_cg[0]/_area;
    	V_cg[1]=V_cg[1]/_area;
    	
    	return V_cg;
    };
    
    double* ellipse_radius(double* _central_inertial_moment, double _area)
    {
    	double* V_ellipse_radius;
    	V_ellipse_radius=(double*)malloc(2*sizeof(double));
    	
    	V_ellipse_radius[0]=sqrt(_central_inertial_moment[0]/_area);
    	V_ellipse_radius[1]=sqrt(_central_inertial_moment[1]/_area);
    	
    	return V_ellipse_radius;
    };
    
    double rotation_angle(double* _inertial_moment)
    {
    	if ( _inertial_moment[2] != 0 ) 
    		return (double)(0.5*atan(((-2)*_inertial_moment[2])/(_inertial_moment[0]-_inertial_moment[1])));
    	else 
    		return 0.0;
    };
    
    double* central_inertial_moment(double* _inertial_moment)
    {
    	double* V_iner_cent_temp;
    	V_iner_cent_temp=(double*)malloc(2*sizeof(double));
    	
    	if ( _inertial_moment[2] != 0 )
    	{
    		if ( _inertial_moment[0]>=_inertial_moment[1] )
    		{
    			V_iner_cent_temp[0]=_inertial_moment[0];
    			V_iner_cent_temp[1]=_inertial_moment[1];
    			
    			return V_iner_cent_temp;
    		}
    		else
    		{
    			V_iner_cent_temp[1]=_inertial_moment[0];
    			V_iner_cent_temp[0]=_inertial_moment[1];
    			
    			return V_iner_cent_temp;
    		}
    	}
    	else
    	{ 
    		
    		V_iner_cent_temp[1]=(0.5*(_inertial_moment[0]+_inertial_moment[1])+sqrt(pow((0.5*fabs((_inertial_moment[0]-_inertial_moment[1]))),2.0)+pow(_inertial_moment[2],2.0)));
    		V_iner_cent_temp[2]=(0.5*(_inertial_moment[0]+_inertial_moment[1])-sqrt(pow((0.5*fabs((_inertial_moment[0]-_inertial_moment[1]))),2.0)+pow(_inertial_moment[2],2.0)));
    		
    		return V_iner_cent_temp;
    	}
    };
    
    double* inertial_moment(double* __cg)
    {
    	double* V_inertial_moment;
    	V_inertial_moment=(double*)malloc(3*sizeof(double));
    	int Counter=0;
    	
    	while ( Counter <= (GL_Objects-1) )
    	{
    		double* V_temp_im;
    		V_temp_im=(double*)malloc(3*sizeof(double));
    		V_temp_im=rectangle[Counter].absolute_inertial_moment(__cg);
    		
    		int i=0;
    		
    		for (i=0; i<3; i++)
    			V_inertial_moment[i]=V_inertial_moment[i]+V_temp_im[i];
    		
    		free((void*)V_temp_im);
    		Counter+=1;
    	}
    	
    	return V_inertial_moment;
    }
    
    //Other implementations
    //Implementations of rational calculus
    class Rational
    
    
    //### MAIN ###
    int main()
    {
    	printf("Nirvana1289 2010\n----------------------------------------\nGEOMETRIA DELLE AREE %s \n----------------------------------------\n\n", VERSION);
    	
    	//Obtain datas
    	int Counter=0;
    	
    	do
    	{
    		printf("Inserire il numero di rettangoli che compongono la figura: "); scanf("%d", &GL_Objects);printf("\n");
    	}
    	while ( GL_Objects<=0 );
    	
    	//Creating Objects
    	rectangle=(CLASS_rectangle*)malloc(GL_Objects*sizeof(CLASS_rectangle));
    	
    	while ( Counter <= (GL_Objects-1) )
    	{
    		double temp_vertex_X, temp_vertex_Y, temp_base, temp_height;
    		temp_vertex_X=temp_vertex_Y=temp_base=temp_height=0.0;
    		
    		printf("Rettangolo %d:\n", (Counter+1));
    		printf("Inserire posizione vertice inferiore sinistro (x,y): "); scanf("%lf,%lf",&temp_vertex_X, &temp_vertex_Y); 
    		printf("Inserire base: "); scanf("%lf", &temp_base); 
    		printf("Inserire altezza: "); scanf("%lf", &temp_height); 
    		
    		rectangle[Counter].assign(temp_vertex_X, temp_vertex_Y, temp_base, temp_height);
    			
    		Counter+=1;
    	}
    	
    	//Calculate
    	printf("\nCalcolo...\n");
    	
    	printf("Espansione vettori...\n");
    	GL_cg=(double*)malloc(2*sizeof(double));
    	GL_inertial_moment=(double*)malloc(3*sizeof(double));
    	GL_central_inertial_moment=(double*)malloc(2*sizeof(double));
    	GL_radius_ellipse=(double*)malloc(2*sizeof(double));
    	
    	printf("Definizione risultati...\n");
    	GL_area=area();
    	GL_cg=cg(GL_area);
    	GL_inertial_moment=inertial_moment(GL_cg);
    	GL_angle=rotation_angle(GL_inertial_moment);
    	GL_Definition_switch=definition_central_rotation(GL_inertial_moment);
    	GL_central_inertial_moment=central_inertial_moment(GL_inertial_moment);
    	GL_radius_ellipse=ellipse_radius(GL_central_inertial_moment, GL_area);
    	
    	printf("... completato!\n");
    	
    	//Printing results
    	printf("\n--- RISULTATI ---\n");
    	
    	printf("\n1 - BARICENTRO\n\n");
    	printf("Oggetto     \t       Area\t    Baricentro (relativo)\n\n");
    	Counter=0;
    	while ( Counter<=(GL_Objects-1) )
    	{
    		printf("Rettangolo %d\t%7.3g m^2\t%7.3g m\t%7.3g m\n", (Counter+1), rectangle[Counter].PB_area, rectangle[Counter].PB_relative_cg[0], rectangle[Counter].PB_relative_cg[1]);
    		Counter+=1;
    	}
    	printf("\nSistema        \t%7.3g m^2\t%7.3g m\t%7.3g m\n", GL_area, GL_cg[0], GL_cg[1]);
    	
    	printf("\n2 - MOMENTO DI INERZIA (relativo al G dei rettangoli)\n\n");
    	printf("Oggetto     \t   MomIn x'\t   MomIn y'\t MomIn x'y'\n\n");
    	Counter=0;
    	while ( Counter<=(GL_Objects-1) )
    	{
    		printf("Rettangolo %d\t%7.3g m^4\t%7.3g m^4\t%7.3g m^4\n", (Counter+1), rectangle[Counter].PB_relative_inertial_moment[0], rectangle[Counter].PB_relative_inertial_moment[1], rectangle[Counter].PB_relative_inertial_moment[2]);
    		Counter+=1;
    	}
    		
    	printf("\n3 - MOMENTO DI INERZIA (relativo al G del sistema)\n\n");
    	printf("Oggetto     \t   MomIn X\t    MomIn Y\t   MomIn XY\n\n");
    	printf("Sistema        \t%7.3g m^4\t%7.3g m^4\t%7.3g m^4\n", GL_inertial_moment[0], GL_inertial_moment[1], GL_inertial_moment[2]);
    	
    	printf("\n4 - MOMENTI CENTRALI DI INERZIA\n\n");
    	switch (GL_Definition_switch)
    	{
    		case UNDEFINED:
    			printf("ERRORE :(\n");
    		break;
    		case DEF_X:
    			printf("[PSI] -> rotazione di X\n[ETA] -> rotazione di Y\n");
    		break;
    		case DEF_Y:
    			printf("[PSI] -> rotazione di Y\n[ETA] -> rotazione di X\n");
    		break;
    	}
    	printf("\nAngolo di rotazione: %7.3g rad\n", GL_angle);
    	printf("\nMomenti centrali di inerzia:\nMomIn[PSI] = %7.3g m^4\nMomIn[ETA] = %7.3g m^4\n", GL_central_inertial_moment[0], GL_central_inertial_moment[1]);
    	
    	printf("\n5 - RAGGI ELLISSE DI INERZIA\n\n");
    	printf("[RHO][PSI] = %7.3g m\n[RHO][ETA] = %7.3g m\n",GL_radius_ellipse[0],GL_radius_ellipse[1]);
    	
    	printf("\n...DONE... CIAO CIAO :P\n");
    	
    	Counter=0;
    	while ( Counter<=(GL_Objects-1) )
    	{
    		rectangle[Counter].~CLASS_rectangle();
    		Counter+=1;
    	}
    	return 0;
    };

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.