/// <example> /// <code lang="CS"> /// using System; /// using Genetibase.MathX.Core; /// /// namespace Genetibase.MathX.Core.Tests /// { /// public class ParametricSurfaceSample /// { /// [STAThread] /// static void Main(string[] args) /// { /// // create function /// ParametricSurface function = new ParametricSurface("u+v","u-v","u*v"); /// /// // calculate function _Function; /// for (int u = 0; u < 100; u++) /// for (int v = 0; v < 100; v++) /// { /// Console.WriteLine("f({0},{1}) = ({2},{3},{4})", /// u,v,function.ValueAt(u,v).X,function.ValueAt(u,v).Y, /// function.ValueAt(u,v).Z); /// } /// /// } /// } /// } /// </code> /// </example> public ParametricSurface(string expressionX, string expressionY, string expressionZ) { if (expressionX == null) { throw new ArgumentNullException("expressionX"); } if (expressionY == null) { throw new ArgumentNullException("expressionY"); } if (expressionZ == null) { throw new ArgumentNullException("expressionZ"); } _expressionTreeX = new ExpressionTree(expressionX); _expressionTreeY = new ExpressionTree(expressionY); _expressionTreeZ = new ExpressionTree(expressionZ); if (_expressionTreeX.Variables.Length > 2) { throw new ArgumentException("expressionX"); } if (_expressionTreeY.Variables.Length > 2) { throw new ArgumentException("expressionY"); } if (_expressionTreeZ.Variables.Length > 2) { throw new ArgumentException("expressionZ"); } _expressionX = expressionX; _expressionY = expressionY; _expressionZ = expressionZ; _expression = string.Format("{0};{1};{2}", _expressionX, _expressionY, _expressionZ); ExpressionCompiler compiler = new ExpressionCompiler(new ExpressionTree[] { _expressionTreeX, _expressionTreeY, _expressionTreeZ }); _functionX = FunctionFactory.CreateRealFunction(_expressionTreeX); _functionY = FunctionFactory.CreateRealFunction(_expressionTreeY); _functionZ = FunctionFactory.CreateRealFunction(_expressionTreeZ); _function = (ParametricSurfaceDelegate)compiler.CreateDelegate(typeof(ParametricSurfaceDelegate), "return new Point3D({0},{1},{2});"); base._delegate = _function; base._definitionType = DefinitionType.Analytic; }
/// <example> /// <code lang="CS"> /// using System; /// using Genetibase.MathX.Core; /// /// namespace Genetibase.MathX.Core.Tests /// { /// public class Parameter3DFunctionSample /// { /// [STAThread] /// static void Main(string[] args) /// { /// // create function /// Parameter3DFunction function = new Parameter3DFunction("10*sin(t)","10*cos(t)", "10*tan(t)"); /// /// // calculate function _Function; /// for (int i = 0; i < 100; i++) /// { /// Console.WriteLine("f({0}) = ({1},{2},{3})",i,function.ValueAt(i).X,function.ValueAt(i).Y, function.ValueAt(i).Z); /// } /// /// } /// } /// } /// </code> /// </example> /// <summary><para>Initializes a function that defined by expression.</para></summary> public Parameter3DFunction(string expressionX, string expressionY, string expressionZ) { if (expressionX == null) { throw new ArgumentNullException("expressionX"); } if (expressionY == null) { throw new ArgumentNullException("expressionY"); } if (expressionZ == null) { throw new ArgumentNullException("expressionZ"); } _expressionTreeX = new ExpressionTree(expressionX); _expressionTreeY = new ExpressionTree(expressionY); _expressionTreeZ = new ExpressionTree(expressionZ); if (_expressionTreeX.Variables.Length > 1) { throw new ArgumentException("expressionX"); } if (_expressionTreeY.Variables.Length > 1) { throw new ArgumentException("expressionY"); } if (_expressionTreeZ.Variables.Length > 1) { throw new ArgumentException("expressionZ"); } _expressionX = expressionX; _expressionY = expressionY; _expressionZ = expressionZ; _expression = string.Format("{0};{1};{2}", _expressionX, _expressionY, _expressionZ); _functionX = FunctionFactory.CreateRealFunction(_expressionTreeX); _functionY = FunctionFactory.CreateRealFunction(_expressionTreeY); _functionZ = FunctionFactory.CreateRealFunction(_expressionTreeZ); _function = DelegateFactory.CreateParameter3DFunctionDelegate( _functionX.ValueAt, _functionY.ValueAt, _functionZ.ValueAt); base._delegate = _function; base._definitionType = DefinitionType.Analytic; }