Exemple #1
0
        public override FP ComputeSubmergedArea(ref TSVector2 normal, FP offset, ref Transform xf, out TSVector2 sc)
        {
            sc = TSVector2.zero;

            TSVector2 p = MathUtils.Mul(ref xf, Position);
            FP        l = -(TSVector2.Dot(normal, p) - offset);

            if (l < -Radius + Settings.Epsilon)
            {
                //Completely dry
                return(0);
            }
            if (l > Radius)
            {
                //Completely wet
                sc = p;
                return(Settings.Pi * _2radius);
            }

            //Magic
            FP l2   = l * l;
            FP area = _2radius * (FP)((TSMath.Asin((l / Radius)) + TSMath.PiOver2) + l * TSMath.Sqrt(_2radius - l2));
            // TODO - PORT
            //FP com = -2.0f / 3.0f * (FP)Math.Pow(_2radius - l2, 1.5f) / area;
            //FP com = new FP(-2) / new FP(3) * (FP)Math.Pow((_2radius - l2).AsFloat(), 1.5f) / area;
            FP com = new FP(-2) / new FP(3) * TSMath.Pow(_2radius - l2, (FP)1.5) / area;

            sc.x = p.x + normal.x * com;
            sc.y = p.y + normal.y * com;

            return(area);
        }
Exemple #2
0
        private FP GetPercent(FP distance, FP radius)
        {
            //(1-(distance/radius))^power-1
            // TODO - PORT
            // FP percent = (FP)Math.Pow(1 - ((distance - radius) / radius), Power) - 1;
            //FP percent = (FP)Math.Pow((1 - ((distance - radius) / radius)).AsFloat(), Power.AsFloat()) - 1;
            FP percent = TSMath.Pow(FP.One - ((distance - radius) / radius), Power) - FP.One;

            if (FP.IsNaN(percent))
            {
                return(FP.Zero);
            }

            return(TSMath.Clamp(percent, FP.Zero, FP.One));
        }
Exemple #3
0
        public FP Distance(FP x, FP y)
        {
            FP distanceSquared = 0;
            FP greatestMin     = TSMath.Max(X1, x);
            FP leastMax        = TSMath.Min(X2, x);

            if (greatestMin > leastMax)
            {
                distanceSquared += TSMath.Pow(greatestMin - leastMax, 2);
            }
            greatestMin = TSMath.Max(Y1, y);
            leastMax    = TSMath.Min(Y2, y);
            if (greatestMin > leastMax)
            {
                distanceSquared += TSMath.Pow(greatestMin - leastMax, 2);
            }

            return((FP)TSMath.Sqrt(distanceSquared));
        }