예제 #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;

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

            return(area);
        }
예제 #2
0
        public override FP ComputeSubmergedArea(ref TSVector2 normal, FP offset, ref Transform xf, out TSVector2 sc)
        {
            sc = TSVector2.zero;
            TSVector2 tSVector = MathUtils.Mul(ref xf, this.Position);
            FP        fP       = -(TSVector2.Dot(normal, tSVector) - offset);
            bool      flag     = fP < -base.Radius + Settings.Epsilon;
            FP        result;

            if (flag)
            {
                result = 0;
            }
            else
            {
                bool flag2 = fP > base.Radius;
                if (flag2)
                {
                    sc     = tSVector;
                    result = Settings.Pi * this._2radius;
                }
                else
                {
                    FP y   = fP * fP;
                    FP fP2 = this._2radius * (TSMath.Asin(fP / base.Radius) + TSMath.PiOver2 + fP * TSMath.Sqrt(this._2radius - y));
                    FP y2  = new FP(-2) / new FP(3) * Math.Pow((double)(this._2radius - y).AsFloat(), 1.5) / fP2;
                    sc.x   = tSVector.x + normal.x * y2;
                    sc.y   = tSVector.y + normal.y * y2;
                    result = fP2;
                }
            }
            return(result);
        }