Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Running c#

Posted on 2013-06-06
5
Medium Priority
?
166 Views
Last Modified: 2013-06-12
Hi,

How  can I run the following c# code in a web page and get the result? the input file is
http://orion.math.iastate.edu/burkardt/data/stl/bottle.stl

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


thanks

ayha
0
Comment
Question by:ayha1999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 42

Assisted Solution

by:Meir Rivkin
Meir Rivkin earned 500 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.
0
 
LVL 7

Expert Comment

by:Alex_W
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.
0
 
LVL 7

Author Comment

by:ayha1999
ID: 39225890
How can I call the function in a page load event?
0
 
LVL 7

Accepted Solution

by:
Alex_W earned 500 total points
ID: 39225942
protected void Page_Load(object sender, EventArgs e)
    {
        ClassLibraryName.ClassName.PublicMethodName();
    }
0
 
LVL 7

Author Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

609 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