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


C# Scientrace.perish方法代码示例

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


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

示例1: traceLeavesEnvironment

        public Scientrace.Location traceLeavesEnvironment(Scientrace.Trace trace)
        {
            trace.currentObject = this;
            Scientrace.Line line = trace.traceline;
            UnitVector dir = line.direction;
            dir.check();
            Vector loc = line.startingpoint;
            /* find locations where line leaves a sphere of radius this.radius around 0,0,0
             * derivation:
             * r^2 = |l*dir + loc|^2
             * hence:
             * 0 = l^2 * |dir|^2 + 2*l*|dir.loc| + |loc|^2 - r^2    //the "." represents a dotproduct
             * Solve ABC formula for l:
             * a = |dir|^2
             * b = 2 * (loc . dir)
             * c = |loc|^2 - r^2 */
            double a = Math.Pow(dir.x,2)+Math.Pow(dir.y,2)+Math.Pow(dir.z,2);
            double b = 2*(loc.x*dir.x+loc.y*dir.y+loc.z*dir.z);
            double c = Math.Pow(loc.x,2)+Math.Pow(loc.y,2)+Math.Pow(loc.z,2)-(Math.Pow(this.radius,2));
            double discriminant = Math.Pow(b,2) - 4* a*c;
            if (discriminant < 0) {
                throw new ArgumentOutOfRangeException("Trace leaves environment from within environment. Are the boundaries of your environment perhaps smaller than your objects?\n Environment radius: "+this.radius+"\n Trace data:"+trace.ToString());
                }
            //ABC formula
            double ans1 = (-b + Math.Sqrt(discriminant)) / (2*a);
            double ans2 = (-b - Math.Sqrt(discriminant)) / (2*a);
            double ans = Math.Max(ans1,ans2);
            //Console.WriteLine("\n"+ans.ToString()+" * "+dir.trico()+"( = "+(dir*ans).trico()+") +"+loc.trico()+" = "+((dir*ans)+loc).toLocation().ToCompactString()+" is ...");
            //			throw new AccessViolationException();
            //Console.WriteLine("IT ENDS HERE: "+((dir*Math.Max(ans1,ans2))+loc).toLocation().ToString());

            Scientrace.Location leavelocation = (dir*ans+loc).toLocation();
            /*			Console.WriteLine("Direction: "+dir.trico()+
                "ABS ANS: "+(Math.Pow(b,2) - 4* a*c)+
                "Location: "+loc.trico());*/
            trace.perish(leavelocation);
            return leavelocation;
        }
开发者ID:JoepBC,项目名称:scientrace,代码行数:38,代码来源:Object3dEnvironment.cs


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