## Introduction

This article describes very briefly (and on a basic level) how to plot user interactive 3D R2 in R surfaces using C# ASP.NET. The example enables the user to interact with the drawing in 5 aspects as below:

- function expression z = f(x,y)
- domain
- integration step
- rotation about x, y and z axis
- model (wireframe or fill)

## Background

- A point in R3 is a set of 3 float values (x,y,z) which defines a position.
- R2 in R functions are expresions in the form z = f(x,y) where x and y are a subset of the function domain.
- The R2 in R domain is the R2 or better, the xy plane.

^{The cartesian coordinates}

The objective is to get a set of z coordinates applying a generic function z=f(x,y) to a discrete domain, or better a matrix of defined x and y points as the image grid above.

### How to Perform This

At first we need to define the domain. Let's choose [-1.7,1.3] for x and [-2.1,2.5] for y what means x will run from -1.7 to 1.3 and y will run from -2.1 to 2.5.

### How to Run the Points

As we are working with R coordinates we have infinite points between 2 coordinates, so for this we need a step variable, which means the integration we will use to get the grid points.

Let's define our step as 0.1, and now we can show some code:

double x0=-1.7, x1=1.3, y0=-2.1, y1=2.5;
double step = 0.1;
double x=x0;
while(x<=x1)
{
y=y0;
while(y<=y1)
{
y+=step;
}
x+=step;
}

Now with above definitions we can handle a generation of z coordinates from running the xy discrete subdomain by using the generic function z = f(x,y)

double x0=-1.7, x1=1.3, y0=-2.1, y1=2.5;
double step = 0.1;
double x=x0;
double z;
while(x<=x1)
{
y=y0;
while(y<=y1)
{
y+=step;
z = function(x,y);
}
x+=step;
}

### Now the Tricky Part

We could use a `MathExpressionParser`

with the expression string, but here I made it more simple with the help of a template with a tag. The process is easy: read the template file, replace the tag, and write the ASPX file which shows the image.

string contents = ReadFile(Server.MapPath("./dynafuncapp.txt"));
contents = contents.Replace("@EXPRESSION", functionStr);
SaveFile(Server.MapPath("./dynacontent.aspx"), contents);

## Putting Everything Together

### The Template File

<%@ Page Language="c#" Debug="true" Explicit="True" %>
<%@ Import Namespace="System.Data" %>

### The Main File

<%@ Page Language="c#" Debug="true" Explicit="True" %>
<%@ Import Namespace="System.Data" %>

^{Sample of generated function
sin(pow(x,3)-7*x*y-pow(y,4))}