Running c#

Posted on 2013-06-06
Last Modified: 2013-06-12

How  can I run the following c# code in a web page and get the result? the input file is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1
    public class Algorithm
        private Mesh _mesh { get; set; }

        public Algorithm(Mesh mesh)
            _mesh = mesh;

        private double SignedVolumeOfTriangle(Vector3 p1, Vector3 p2, Vector3 p3)
            var v321 = p3.X * p2.Y * p1.Z;
            var v231 = p2.X * p3.Y * p1.Z;
            var v312 = p3.X * p1.Y * p2.Z;
            var v132 = p1.X * p3.Y * p2.Z;
            var v213 = p2.X * p1.Y * p3.Z;
            var v123 = p1.X * p2.Y * p3.Z;
            return (1.0 / 6.0) * (-v321 + v231 + v312 - v132 - v213 + v123);

        public double VolumeOfMesh()
            double volume = 0.0;

            Vector3[] vertices = _mesh.Vertices;
            int[] triangles = _mesh.Triangles;

            for (int i = 0; i < _mesh.Triangles.Length; i += 3)
                Vector3 p1 = vertices[triangles[i + 0]];
                Vector3 p2 = vertices[triangles[i + 1]];
                Vector3 p3 = vertices[triangles[i + 2]];

                volume += SignedVolumeOfTriangle(p1, p2, p3);

            return Math.Abs(volume);

    public class Mesh
        public Mesh(Vector3[] _vertices, int[] _triangles)
            Vertices = _vertices;
            Triangles = _triangles;

        public Vector3[] Vertices { get; set; }

        public int[] Triangles { get; set; }

    public class Vector3
        public Vector3(double x, double y, double z)
            X = x;
            Y = y;
            Z = z;

        public double X { get; set; }
        public double Y { get; set; }

        public double Z { get; set; }

Open in new window


Question by:ayha1999
  • 2
  • 2
LVL 42

Assisted Solution

sedgwick earned 125 total points
ID: 39225333
create class library and add this class Algorithm to the library.
compile it and then add the dll to your web project.

Expert Comment

ID: 39225702
Then on your UI page you can call the functions in your class library to test it and step through the code if required.

Author Comment

ID: 39225890
How can I call the function in a page load event?

Accepted Solution

Alex_W earned 125 total points
ID: 39225942
protected void Page_Load(object sender, EventArgs e)

Author Comment

ID: 39226009
This code is for calculating volume of stl files. where can I provide the stl file in the code?

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
which object should i use (efficiency) 5 45
Visual Studio Publish Web Configuration does not contain Release 5 19
Name space syntax error 12 39
Error in JQuery 5 36
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now