本文整理汇总了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;
}