2

I would like to make a simple web application (a static website where all computation happens on the client) that generates a mesh and displays it. I have a working prototype in Unity and now I'm wondering what a good framework / language is for the task.

The problem: I would like to use Typescript or Javascript, but neither support operator overloading.

A line like this in C#

a = Vector3.forward * 3 + direction * length * 0.5;

would look horrible without operator overloading:

a = Vector3.forward.times(3).add(direction.times(length * 0.5));

What is the most elegant solution to this?

asked Feb 18, 2019 at 21:07
16
  • 1
    This question is in no way special to web development, so I took the freedom to remove that distracting noise from the title and and the tags. Commented Feb 19, 2019 at 12:13
  • 1
    Why do you feel you need to rewrite your application in a different language in order to present data in a browser? Commented Feb 19, 2019 at 13:05
  • @PeterM I would like to generate and present the data inside a website, wihtout a server. I updated the question to be more specific. I know that you can transpile C# to Javascript, but that creates a lot of overhead. Commented Feb 19, 2019 at 19:17
  • 1
    @Toast Or if you really want to punish you can compile your c# to webassembly Commented Feb 19, 2019 at 23:19
  • 2
    @Toast I don't think I understand what you are trying to do. Are you saying that you have built a 3D scene in Unity and now you need to replicate that scene in a stand alone file that can be loaded by a browser? Or do you want to cast your existing Unity program into a browser? Commented Feb 19, 2019 at 23:25

1 Answer 1

7

You either pick a language that allows the syntax you want, or write it out longhand and accept that it "look[s] horrible".

For vector arithmetic, there are at least 3 different operations that are reasonably denoted by * (or times or product), and you'd have to have a language that takes return types into account to disambiguate all of them. It's then not such a burden to have to name scale, dot product and cross product.

As a note, it's likely there are existing linear algebra libraries in all the languages that you could use. Don't try to write one yourself unless you really can't find one.

answered Feb 19, 2019 at 12:38
4
  • Could you name an example of a language that offers operator overloading and works well on a webpage? For me it's sufficient if the * operator only works for scaling, not the dot product or cross product. Commented Feb 19, 2019 at 19:19
  • @Toast C# is fine for generating html. Commented Feb 19, 2019 at 22:59
  • Webbrowsers can't run C#. Commented Feb 19, 2019 at 23:06
  • 1
    Soon you'll be able to compile C# to wasm, then the browser can run that. Commented Feb 20, 2019 at 0:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.