示例#1
0
文件: eli.c 项目: tkoziara/solfec
/* create an ellipsoid */
ELLIP* ELLIP_Create (double *center, double *radii, int surface, int volume)
{
  ELLIP *eli;

  ERRMEM (eli = malloc (sizeof (ELLIP)));

  COPY (center, eli->ref_center);
  COPY (center, eli->ref_point [0]); eli->ref_point[0][0] += radii [0];
  COPY (center, eli->ref_point [1]); eli->ref_point[1][1] += radii [1];
  COPY (center, eli->ref_point [2]); eli->ref_point[2][2] += radii [2];

  COPY (center, eli->cur_center);
  COPY (center, eli->cur_point [0]); eli->cur_point[0][0] += radii [0];
  COPY (center, eli->cur_point [1]); eli->cur_point[1][1] += radii [1];
  COPY (center, eli->cur_point [2]); eli->cur_point[2][2] += radii [2];

  COPY (radii, eli->ref_sca);
  COPY (radii, eli->cur_sca);
  IDENTITY (eli->ref_rot);
  IDENTITY (eli->cur_rot);

  eli->surface = surface;
  eli->volume = volume;
  eli->mat = NULL;

  return eli;
}
示例#2
0
文件: eli.c 项目: tkoziara/solfec
/* compute partial characteristic: 'vo'lume and static momenta
 * 'sx', 'sy, 'sz' and 'eul'er tensor; assume that all input data is initially zero; */
void ELLIP_Char_Partial (ELLIP *eli, int ref, double *vo, double *sx, double *sy, double *sz, double *eul)
{
  double v, a, b, c, e, *x, *R, tmp [9], tmq [9], eye [9];

  if (ref)
  {
    ELLIP *elj = ELLIP_Copy (eli);
    ELLIP_Update (elj, NULL, NULL, NULL);
    ELLIP_Char_Partial (elj, 0, vo, sx, sy, sz, eul);
    ELLIP_Destroy (elj);
    return;
  }

  R = eli->cur_rot;
  x = eli->cur_center;
  a = eli->cur_sca [0];
  b = eli->cur_sca [1];
  c = eli->cur_sca [2];
  v = (4.0/3.0)*ALG_PI*a*b*c;

  /* Stainer's theorem =>
   * J(i, j) = I(i, j) + M*(<x,x> * delta (i, j) - diadic (x, x))
   * hence it is possible to produce inertia tensor with respect
   * to the origin from one with respect to the center point */

  e = DOT (x, x);
  IDENTITY (eye);
  SCALEDIAG (eye, e);
  DIADIC (x, x, tmp);
  NNSUB (eye, tmp, tmp);
  SCALE9 (tmp, v);
  IDENTITY (eye); /* prepare I0 (i, j) */
  eye [0] = v * (b*b + c*c) / 5.0;
  eye [4] = v * (a*a + c*c) / 5.0;
  eye [8] = v * (b*b + a*a) / 5.0;
  NTMUL (eye, R, tmq);
  NNMUL (R, tmq, eye); /* I1 (i, j) = R I0 R' */
  NNADD (eye, tmp, tmp); /* tmp = inertia of the sphere with respect to x, y, z passing 0 (see above) */

  /* note that Inertia = Trace(Euler)*Identity - Euler,
   * hence Euler = 0.5 * Trace (Inertia)*Identity - Inertia,
   * as Trace(Inertia) = 3*Trace(Euler) - Trace(Euler) */

  e = 0.5 * TRACE (tmp);
  IDENTITY (eye);
  SCALEDIAG (eye, e);
  NNSUB (eye, tmp, tmp); /* tmp = euler tensor with repsect to x, y, z passing 0 */

  /* sum up */
  *vo += v;
  *sx += v * x [0];
  *sy += v * x [1];
  *sz += v * x [2];
  NNADD (tmp, eul, eul);

  /* TODO: make sure the above is correct */
}
示例#3
0
/* compute partial characteristic: 'vo'lume and static momenta
 * 'sx', 'sy, 'sz' and 'eul'er tensor; assume that all input data is initially zero; */
void SPHERE_Char_Partial (SPHERE *sph, int ref, double *vo, double *sx, double *sy, double *sz, double *eul)
{
  double v, e, r, *a, tmp [9], eye [9];

  r = ref ? sph->ref_radius : sph->cur_radius;
  a = ref ? sph->ref_center : sph->cur_center;
  v = (4.0/3.0)*ALG_PI*r*r*r;

  /* Stainer's theorem =>
   * J(i, j) = I(i, j) + M*(a^2 * delta (i, j) - diadic (a, a))
   * hence it is possible to produce inertia tensor with respect
   * to the origin from one with respect to the center point */

  e = DOT (a, a);
  IDENTITY (eye);
  SCALEDIAG (eye, e);
  DIADIC (a, a, tmp);
  NNSUB (eye, tmp, tmp);
  SCALE9 (tmp, v);
  e = (2.0/5.0)*v*r*r; /* diagonal entry of sphere inertia tensor */
  IDENTITY (eye);
  SCALEDIAG (eye, e);
  NNADD (eye, tmp, tmp); /* tmp = inertia of the sphere with respect to x, y, z passing 0 (see above) */

  /* note that Inertia = Trace(Euler)*Identity - Euler,
   * hence Euler = 0.5 * Trace (Inertia)*Identity - Inertia,
   * as Trace(Inertia) = 3*Trace(Euler) - Trace(Euler) */

  e = 0.5 * TRACE (tmp);
  IDENTITY (eye);
  SCALEDIAG (eye, e);
  NNSUB (eye, tmp, tmp); /* tmp = euler tensor with repsect to x, y, z passing 0 */

  /* sum up */
  *vo += v;
  *sx += v * a [0];
  *sy += v * a [1];
  *sz += v * a [2];
  NNADD (tmp, eul, eul);

  /* TODO: make sure the above is correct */
}
示例#4
0
文件: mesh.cpp 项目: tkoziara/parmec
/* calculate mass characteristics: scalar mass, mass center, inertia tensor */
void MESH_Char (MESH_DATA *msh, REAL *mass, REAL *center, REAL *inertia)
{
  REAL me, sx, sy, sz, euler [9];
  ELEMENT *ele;

  me = sx = sy = sz = 0.0;
  SET9 (euler, 0.0);

  for (ele = msh->bulkeles; ele; ele = ele->next)
    element_char_add (msh, ele, &me, &sx, &sy, &sz, euler);

  for (ele = msh->surfeles; ele; ele = ele->next)
    element_char_add (msh, ele, &me, &sx, &sy, &sz, euler);

  mass[0] = me;

  center [0] = sx / me;
  center [1] = sy / me;
  center [2] = sz / me;

  euler [0] -= (2*sx - center[0]*me)*center[0];
  euler [4] -= (2*sy - center[1]*me)*center[1];
  euler [8] -= (2*sz - center[2]*me)*center[2];
  euler [3] -= center[0]*sy + center[1]*sx - center[0]*center[1]*me;
  euler [6] -= center[0]*sz + center[2]*sx - center[0]*center[2]*me;
  euler [7] -= center[1]*sz + center[2]*sy - center[1]*center[2]*me;
  euler [1] = euler[3];
  euler [2] = euler[6];
  euler [5] = euler[7];

  /* convert Euler tensor to the inertia tensor */
  REAL trace = TRACE (euler);
  IDENTITY (inertia);
  SCALE9 (inertia, trace);
  NNSUB (inertia, euler, inertia); /* inertia = tr(euler)*one - euler */
}
示例#5
0
bool QuaternionTest::test()
{
    // ctor tests
    Quaterniond tquaternion_test( 8., 1., 6., 3. );
    for ( size_t i = 0; i < 4; ++i )
    {
        if ( _quaternion.wxyz[i] != tquaternion_test.wxyz[i] )
        {
            cout << "test: Quaternion::Quaternion( ... ) failed!" << endl;
            failed();
            assert( 0 );            
        }
	}
	
	Quaterniond squaternion_test( 8., Vector3d( 1., 6., 3. ) );
	for ( size_t i = 0; i < 4; ++i )
	{
		if ( _quaternion.wxyz[i] != squaternion_test.wxyz[i] )
		{
            cout << "test: Quaternion::Quaternion( ... ) failed!" << endl;
            failed();
            assert( 0 );            
        }
	}
	
	Quaterniond uquaternion_test( Matrix3d( 1., 0., 0., 0., 0., 1., 0., -1., 0. ) );
	for ( size_t i = 0; i < 4; ++i )
	{
		if ( i == 0  )
			if ( uquaternion_test.wxyz[0] != ( sqrt( 2. ) / 2. ) )
				{
					cout << "test: Quaternion::Quaternion( ... ) failed!" << endl;
					failed();
					assert( 0 );            
				}
		if ( i == 1  )
			if ( uquaternion_test.wxyz[1] != - ( 1 / sqrt( 2. ) ) )
				{
					cout << "test: Quaternion::Quaternion( ... ) failed!" << endl;
					failed();
					assert( 0 );            
				}
		if ( i != 0 && i != 1 )
			if ( uquaternion_test.wxyz[i] != 0. )
				{
					cout << "test: Quaternion::Quaternion( ... ) failed!" << endl;
					failed();
					assert( 0 );            
				}

	}
	
	// set test
	uquaternion_test.set ( 8., 1., 6., 3. );
	for ( size_t i = 0; i < 4; ++i )
	{
		if ( _quaternion.wxyz[i] != uquaternion_test.wxyz[i] )
		{
            cout << "test: Quaternion::set( ... ) failed!" << endl;
            failed();
            assert( 0 );            
        }
	}
	 
	// operator = tests
	tquaternion_test = 1.;
	Quaterniond IDENTITY( 1., 0., 0., 0. );
	for ( size_t i = 0; i < 4; ++i )
	{
		if ( IDENTITY.wxyz[i] != tquaternion_test.wxyz[i] )
		{
            cout << "test: Quaternion::operator=( ... ) failed!" << endl;
            failed();
            assert( 0 );            
        }
	}
	
	uquaternion_test = _quaternion;
	for ( size_t i = 0; i < 4; ++i )
	{
		if ( _quaternion.wxyz[i] != uquaternion_test.wxyz[i] )
		{
            cout << "test: Quaternion::operator=( ... ) failed!" << endl;
            failed();
            assert( 0 );            
        }
	}
	
	//quaternion == / != tests
	if ( tquaternion_test != 1. )
    {
        cout << "test: Quaternion::operator ==() / !=() failed!" << endl;
        failed();
        assert( 0 );
    }  
	
	if ( _quaternion != uquaternion_test )
    {
        cout << "test: Quaternion::operator ==() / !=() failed!" << endl;
        failed();
        assert( 0 );
    }  
	
	if ( _quaternion == tquaternion_test )
	{
        cout << "test: Quaternion::operator ==() / !=() failed!" << endl;
        failed();
        assert( 0 );
    }  
	
	//abs() test
	if ( _quaternion.abs() !=  sqrt( 110 ) )
    {
        cout << "test: Quaternion::abs() failed!" << endl;
        failed();
        assert( 0 );
    }  
	
	//conjug() test
	Quaterniond cquaternion_test( 8., -1., -6., -3. );
	if ( _quaternion.conjug() != cquaternion_test )
	    {
        cout << "test: Quaternion::conjug() failed!" << endl;
        failed();
        assert( 0 );
    } 
	
	//quaternion/scalar tests
	tquaternion_test.set( 1., 2., 3., 4. );
	Quaterniond vquaternion_test( 3., 6., 9., 12. );
	tquaternion_test = tquaternion_test * 3.0;
	if ( tquaternion_test - vquaternion_test != 0.0 )
	{
        cout << "test: Quaternion::operator*/( scalar ) failed!" << endl;
		cout << tquaternion_test << endl;
        failed();
        assert( 0 );
    }  
	
	// quaternion/quaternion tests
	tquaternion_test.set( 1., 2., 3., 4. );
	if ( tquaternion_test + tquaternion_test + tquaternion_test -vquaternion_test != 0.0f  )
	{
        cout << "test: Quaternion::operator+-( quaternion ) failed!" << endl;
        failed();
        assert( 0 );
    }  
	
	squaternion_test.set( -24., 2., 28., 44 ); 
	
	if ( squaternion_test != tquaternion_test * uquaternion_test )
	{
        cout << "test: Quaternion::operator*( quaternion ) failed!" << endl;
        failed();
        assert( 0 );
    }  
	
	Quaterniond rquaternion_test( 8. / 110., -1. / 110., -6. / 110., -3. / 110. );
	
	if ( _quaternion.invert() != rquaternion_test )
	{
		cout << "test: Quaternion::invert() failed!" << endl;
        failed();
        assert( 0 );
	}
	
	if ( tquaternion_test.dot( _quaternion ) != 40. )
	{
		cout << "test: Quaternion::dot( quaternion ) failed!" << endl;
        failed();
        assert( 0 );
	}
		
	Vector3d vector3_test( -30., -4., 18. );
	if ( tquaternion_test.cross( _quaternion ) != vector3_test )
	{
		cout << "test: Quaternion::cross( quaternion ) failed!" << endl;
        failed();
        assert( 0 );
	}
	
	Vector3d yaxis( 1., 0., 0. );
	Quaterniond svector3_test( 0., 18., -30., -4. );
	Quaterniond result_test( _quaternion.rotate( M_PI / 2.f, yaxis, vector3_test ) );	
	if ( abs( result_test.abs() - svector3_test.abs() ) > 1e-13 )
	{
		cout << "test: Quaternion::rotate( T, Vector3, Vector3 ) failed!" << endl;
		failed();
		assert( 0 );
	}

    if ( ok )
        cout << "Quaternion: all tests passed!" << endl;
		
	return ok;
}
示例#6
0
HRESULT CHveDbController::SaveDBElement(RESULT_ELEMENT* pElement)
{
	HRESULT hr = S_OK;
	if(!m_fIsConnecting)
	{
		SaveLog("数据库连接已经断开,尝试重新连接...");
		hr = ConnectDB();
	}

	if(!m_fIsConnecting)
	{
		char szOutPutInfo[100];
		sprintf(szOutPutInfo, "连接数据库失败,保存%s结果失败...错误码:%d", pElement->szPlateNo, GetLastError());
		SaveLog(szOutPutInfo);
		OutPutMessage(szOutPutInfo);
		return E_FAIL;
	}
	_variant_t RecordsAffected;

	CTime cTime(pElement->dw64TimeMs / 1000);
	CString strTime = cTime.Format("%Y-%m-%d %H:%M:%S");
	CString strCurTable = cTime.Format("Hve_Data_%Y%m%d");

	//int iMinute = cTime.GetMinute(); 
	//CString strTmp = cTime.Format("Hve_Data_%Y%m%d%H");
	//strCurTable.Format("%s_%d",strTmp.GetBuffer(), iMinute/10); // 10分钟一张表
	//strTmp.ReleaseBuffer();

	if(m_strLastTable != strCurTable)
	{
		char szCmdText[1024] = {0};

		//try
		//{
		//	sprintf(szCmdText, "Create TABLE %s(Record_Id bigint primary key IDENTITY   (1,   1)   NOT   NULL,\
		//					   Location_Id int NOT NULL,Pass_Time datetime NOT NULL, Plate_No char(20), Road_No int,\
		//					   Car_Speed int, Obj_Id int, Time_Headway int, Over_Line int, Cross_Line int,\
		//					   Emergency_Stop int, Reverse_Run bit, Special_Result bit, big_image_1_path char(256),\
		//					   big_image_2_path char(256), big_image_3_path char(256), big_image_4_path char(256),\
		//					   big_image_5_path char(256), small_image_path char(256), bin_image_path char(256),\
		//					   video_path char(256))", strCurTable.GetBuffer());
		//	m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);
		//	sprintf(szCmdText, "CREATE INDEX [Pass_Time] ON [dbo].[%s] ([Pass_Time])", strCurTable.GetBuffer());
		//	m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);
		//	sprintf(szCmdText, "CREATE INDEX [Obj_Id] ON [dbo].[%s] ([Obj_Id])", strCurTable.GetBuffer());
		//	m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);
		//	sprintf(szCmdText, "CREATE INDEX [Special_Result] ON [dbo].[%s] ([Special_Result])", strCurTable.GetBuffer());
		//	m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);
		//}

		//表存在则不创建
		try
		{
			sprintf(szCmdText, "if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[%s]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) \
							   Create TABLE %s(Record_Id bigint primary key IDENTITY   (1,   1)   NOT   NULL,\
							   Location_Id int NOT NULL,Pass_Time datetime NOT NULL, Plate_No char(20), Road_No int, Road_Name char(25),Road_Direct char(10),\
							   Car_Speed int, Obj_Id int, Time_Headway int, Over_Line int, Cross_Line int,\
							   Emergency_Stop int, Reverse_Run bit, Speeding bit, Special_Result bit, big_image_1_path varchar(256),\
							   big_image_2_path varchar(256), big_image_3_path varchar(256), big_image_4_path varchar(256),\
							   big_image_5_path varchar(256), small_image_path varchar(256), bin_image_path varchar(256),\
							   video_path varchar(256))",strCurTable.GetBuffer(),strCurTable.GetBuffer());
			m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);
			sprintf(szCmdText, "if not exists (select * from sysindexes where name='Pass_Time')  CREATE INDEX [Pass_Time] ON [dbo].[%s] ([Pass_Time])", strCurTable.GetBuffer());
			m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);
			sprintf(szCmdText, "if not exists (select * from sysindexes where name='Obj_Id') CREATE INDEX [Obj_Id] ON [dbo].[%s] ([Obj_Id])", strCurTable.GetBuffer());
			m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);
			sprintf(szCmdText, "if not exists (select * from sysindexes where name='Special_Result') CREATE INDEX [Special_Result] ON [dbo].[%s] ([Special_Result])", strCurTable.GetBuffer());
			m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);
		}
		catch (_com_error e)
		{
			m_fIsConnecting = FALSE;
			CString strErrorMessage;
			strErrorMessage.Format("创建表失败!错误信息:%s  错误码:%d", e.ErrorMessage(), GetLastError());
			SaveLog(strErrorMessage.GetBuffer());
			SaveLog(e.Description());
			OutPutMessage("创建数据表失败!");
		}

		///////视图创建 由查询软件创建
		//try
		//{
		//	char szCmdText[1024] = {0};
		//	sprintf(szCmdText, "IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N'Hve_Data_View') DROP VIEW Hve_Data_View");
		//	m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);

		//}
		//catch (_com_error e)
		//{
		//	CString strErrorMessage;
		//	strErrorMessage.Format("删除视图失败! 错误信息:%s 错误码:%d", e.ErrorMessage(), GetLastError());
		//	SaveLog(strErrorMessage.GetBuffer());
		//	SaveLog(e.Description());
		//	OutPutMessage("删除视图失败...");
		//}
		
		//bool fIsCreateViewFault = true;
		//int iRetry = 0;
		//while(fIsCreateViewFault)
		//{
		//	if(iRetry++ == 5)
		//	{
		//		exit(1);  //reboot
		//	}

		//	try
		//	{
		//		_RecordsetPtr pPtr;
		//		CString strName;
		//		if(FAILED(pPtr.CreateInstance("ADODB.Recordset")))
		//		{
		//			OutPutMessage("创建ADO数据集失败...");
		//			return E_FAIL;
		//		}

		//		CString strConnectInfo;
		//		strConnectInfo.Format("Driver=SQL Server;Server=%s;DATABASE=%s;UID=%s;PWD=%s",
		//			m_strServerIP, m_strDataBase, m_strUserName, m_strPassword);
		//		CString strCommand = "SELECT name FROM sysobjects WHERE (name LIKE 'Hve_Data_%')";;
		//		if(FAILED(pPtr->Open(_variant_t(strCommand), _variant_t(strConnectInfo), adOpenStatic, adLockOptimistic, adCmdText)))
		//		{
		//			OutPutMessage("获取数据表名字失败...");
		//			pPtr.Release();
		//			return E_FAIL;
		//		}
		//		while(!pPtr->GetadoEOF())
		//		{
		//			CString strTmp = (char*)_bstr_t(pPtr->GetCollect("name"));
		//			strTmp.TrimRight();
		//			if(strName == "")
		//			{
		//				strName.Format("(SELECT * FROM %s)", strTmp);
		//			}
		//			else
		//			{
		//				strName.AppendFormat("union (SELECT * FROM %s)", strTmp);
		//			}
		//			pPtr->MoveNext();
		//		}
		//		pPtr->Close();
		//		pPtr.Release();

		//		char szCmdText[1024] = {0};
		//		sprintf(szCmdText,  "CREATE VIEW Hve_Data_View AS %s", strName);
		//		m_pConnection->Execute((_bstr_t)szCmdText, &RecordsAffected, adCmdText);
		//		fIsCreateViewFault = false;
		//	}
		//	catch (_com_error e)
		//	{
		//		fIsCreateViewFault = true;
		//		CString strErrorMessage;
		//		strErrorMessage.Format("创建视图失败... 错误码:%d", GetLastError());
		//		SaveLog(strErrorMessage.GetBuffer());
		//		SaveLog(e.Description());
		//		OutPutMessage("创建视图失败...");
		//	}
		//}
	
	}