Exemplo n.º 1
0
        public void TestDerivative(double point, double expected)
        {
            Derivative = new Derivative(TypicalFunction);
            var got = Derivative.GetDerivative(point);

            // delta подбирается эмпирическим путём
            Assert.AreEqual(expected, got, 1E-09);
        }
            public void Execute(int index)
            {
                var bufferNoiseEntity = BufferNoiseEntities[index];
                var fromIndex         = bufferNoiseEntity.Fraction * Size;

                for (var i = 0; i < PartSize; i++)
                {
                    var currentIndex = fromIndex + i * 4;
                    var position     = Location.Position(Location.NextIndexes(currentIndex), Resolution);
                    UnsafeUtility.WriteArrayElementWithStride(
                        Normals.GetUnsafePtr(),
                        currentIndex,
                        UnsafeUtility.SizeOf <float3>(),
                        Derivative.GetDerivative(Vertices, position, Resolution)
                        );
                }
            }
Exemplo n.º 3
0
        private Vector3 getNormalAnalitic(string xExpr, string yExpr, string zExpr, string u, string v)
        {
            var d = ":" + u + ";" + v;

            var xonu = Derivative.GetDerivative(xExpr, u, false);
            var xonv = Derivative.GetDerivative(xExpr, v, false);
            var yonu = Derivative.GetDerivative(yExpr, u, false);
            var yonv = Derivative.GetDerivative(yExpr, v, false);
            var zonu = Derivative.GetDerivative(zExpr, u, false);
            var zonv = Derivative.GetDerivative(zExpr, v, false);

            var v1 = new Vector3(xonu + d, yonu + d, zonu + d);
            var v2 = new Vector3(xonv + d, yonv + d, zonv + d);

            var normalNotNormalized = (v1 ^ v2);
            var len = (CommonFunction)("sqrt(" + (normalNotNormalized * normalNotNormalized).Print() + ")" + d);

            return(normalNotNormalized / len);
        }