当前位置: 首页>>代码示例>>C#>>正文


C# Evaluator.EvaluatePositionWithClampedGlobalT方法代码示例

本文整理汇总了C#中Evaluator.EvaluatePositionWithClampedGlobalT方法的典型用法代码示例。如果您正苦于以下问题:C# Evaluator.EvaluatePositionWithClampedGlobalT方法的具体用法?C# Evaluator.EvaluatePositionWithClampedGlobalT怎么用?C# Evaluator.EvaluatePositionWithClampedGlobalT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Evaluator的用法示例。


在下文中一共展示了Evaluator.EvaluatePositionWithClampedGlobalT方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetClosestPointInInterval

            /// <summary>
            /// Minimise the stored distance function over a given interval
            /// </summary>
            /// <param name="eval"> Spline evaluator </param>
            /// <param name="interval"> Interval size </param>
            /// <param name="iterations"> Number of iterations </param>
            /// <returns> Point in interval that minimises stored distance function </returns>
            public float GetClosestPointInInterval( Evaluator eval, float interval, int iterations )
            {
                m_S[ 0 ] = eval.GlobalT;
                m_S[ 1 ] = eval.GlobalT + ( interval / 2 );
                m_S[ 2 ] = eval.GlobalT + interval;

                float minT = m_S[ 0 ];
                float maxT = m_S[ 2 ];

                m_Points[ 0 ] 		= eval.EvaluatePositionWithClampedGlobalT( m_S[ 0 ] );
                m_Points[ 1 ] 		= eval.EvaluatePositionWithClampedGlobalT( m_S[ 1 ] );
                m_Points[ 2 ] 		= eval.EvaluatePositionWithClampedGlobalT( m_S[ 2 ] );

                m_Distances[ 0 ] 	= m_Distance( m_Points[ 0 ] );
                m_Distances[ 1 ] 	= m_Distance( m_Points[ 1 ] );
                m_Distances[ 2 ] 	= m_Distance( m_Points[ 2 ] );

                int BestIndex = 0;
                float ClosestDistance = float.MaxValue;

                for ( int k = 0; k < iterations; ++k )
                {
                    m_S2[ 0 ] = m_S[ 0 ] * m_S[ 0 ];
                    m_S2[ 1 ] = m_S[ 1 ] * m_S[ 1 ];
                    m_S2[ 2 ] = m_S[ 2 ] * m_S[ 2 ];

                    float PolyEstimateNum	=	( ( m_S2[ 1 ] - m_S2[ 2 ] ) * m_Distances[ 0 ] ) +
                                                ( ( m_S2[ 2 ] - m_S2[ 0 ] ) * m_Distances[ 1 ] ) +
                                                ( ( m_S2[ 0 ] - m_S2[ 1 ] ) * m_Distances[ 2 ] );
                    float PolyEstimateDen	=	( (  m_S[ 1 ] -  m_S[ 2 ] ) * m_Distances[ 0 ] ) +
                                                ( (  m_S[ 2 ] -  m_S[ 0 ] ) * m_Distances[ 1 ] ) +
                                                ( (  m_S[ 0 ] -  m_S[ 1 ] ) * m_Distances[ 2 ] );

                    if ( Math.Abs( PolyEstimateDen ) < 0.0001f )
                    {
                        break;
                    }

                    m_S[ 3 ]			= Utils.Clamp( 0.5f * ( PolyEstimateNum / PolyEstimateDen ), minT, maxT );
                    m_Points[ 3 ]		= eval.EvaluatePositionWithClampedGlobalT( m_S[ 3 ] );
                    m_Distances[ 3 ]	= m_Distance( m_Points[ 3 ] );

                    m_PValues[ 0 ] 		= EvaluatePolynomial( m_S[ 0 ] );
                    m_PValues[ 1 ] 		= EvaluatePolynomial( m_S[ 1 ] );
                    m_PValues[ 2 ] 		= EvaluatePolynomial( m_S[ 2 ] );
                    m_PValues[ 3 ] 		= EvaluatePolynomial( m_S[ 3 ] );

                    //	Which estimate created the furthest distance?
                    int		FurthestIndex		= 0;
                    float	FurthestDistance	= -float.MaxValue;
                    for ( int Index = 0; Index < 4; ++Index )
                    {
                        if ( m_PValues[ Index ] > FurthestDistance )
                        {
                            FurthestDistance	= m_PValues[ Index ];
                            FurthestIndex		= Index;
                        }
                    }

                    //	Remake arrays m_S and m_Distances using the 3 closest estimates
                    int AddAt = 0;
                    ClosestDistance = float.MaxValue;
                    for ( int Index = 0; Index < 4; ++Index )
                    {
                        if ( Index != FurthestIndex )
                        {
                            m_S[ AddAt ]			= m_S[ Index ];
                            m_Distances[ AddAt ]	= m_Distances[ Index ];
                            m_Points[ AddAt ]		= m_Points[ Index ];
                            m_PValues[ AddAt ]		= m_PValues[ Index ];

                            if ( m_PValues[ AddAt ] < ClosestDistance )
                            {
                                BestIndex = AddAt;
                            }

                            ++AddAt;
                        }
                    }
                }

                if ( ClosestDistance < m_ClosestDistance )
                {
                    m_ClosestDistance	= ClosestDistance;
                    m_ClosestFraction	= m_S[ BestIndex ];
                }

                return m_ClosestFraction;
            }
开发者ID:johann-gambolputty,项目名称:robotbastards,代码行数:96,代码来源:CatmullRomSpline.cs


注:本文中的Evaluator.EvaluatePositionWithClampedGlobalT方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。