Advertisement

Support functions (for JGK or MPR) for cone?

Started by September 24, 2020 08:30 AM
1 comment, last by MCapousek 4 years, 4 months ago

Hello.

Is there a support function for the cone? I found support function for sphere, box, cylinder, but couldn't find one for cone.

m_SideLng = Math::Sqrt( m_Radius*m_Radius + m_Height*m_Height );

m_SinA = m_Radius / m_SideLng;
m_CosA = m_Height / m_SideLng;

m_R2Hcoef = m_Radius / m_Height;
m_SideDot = m_CosA * m_R2Hcoef;
	
m_P0 ........ center of base
m_P1 ........ top spike
m_Axis[3] ... x,y,z axis


C_Vector3 C_ShapeCone :: GetSupportPoint( C_Vector3 const & dir ) const
{
	const float dy = dir.Dot( m_Axis[1] );

	if( dy >= m_SideDot )
	{
		return m_P1;
	}
	else
	{
		if( dy <= -0.999995f )
			return m_P0;
	
		const float dx = dir.Dot( m_Axis[0] );
		const float dz = dir.Dot( m_Axis[2] );
		const float r  = m_Radius / Math::Sqrt( dx * dx + dz * dz );

		return m_P0 + ( dx * r ) * m_Axis[0] + ( dz * r ) * m_Axis[2];
	}
}

This topic is closed to new replies.

Advertisement