Giter VIP home page Giter VIP logo

enkimute / ganja.js Goto Github PK

View Code? Open in Web Editor NEW
1.5K 36.0 106.0 7.28 MB

:triangular_ruler: Javascript Geometric Algebra Generator for Javascript, c++, c#, rust, python. (with operator overloading and algebraic literals) -

License: MIT License

JavaScript 26.85% C++ 15.95% C# 16.98% Makefile 0.17% Python 16.90% Rust 23.15%
javascript geometric-algebra clifford-algebras complex-numbers quaternion-algebra operator-overloading algebraic-data-types cplusplus csharp rust

ganja.js's People

Contributors

csteinmetz15 avatar enkimute avatar eric-wieser avatar grondilu avatar hugohadfield avatar hugohadfieldwayve avatar joha2 avatar jordibc avatar kungfooman avatar steveyen avatar tionkje avatar utensil avatar waldyrious avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ganja.js's Issues

Dragging issue using width:window.innerWidth option to graph() function

I was just testing out the nifty new SVG attributes and decided to use a wide drawing canvas using the width:window.innerWidth option to the graph() function. However when I then tried to drag points it appears that the conversion between different coordinate systems isn't taking into account this width. It appears that the input works correctly but it draws the output point as if it were drawing in the smaller default window. When I delete the width:window.innerWidth option (defaulting to a 500 pixel square I think) dragging works like it should. See for example https://beta.observablehq.com/@skydog23/the-polarity-with-respect-to-a-conic, drag the point B. Then remove the width:window.innerWidth option and drag B: everything fine.

OpenGL 3D controls

Being able to rotate 3D view is great and really adds to the interactive experience of using ganja but it would be fantastic to be able to tilt the camera up and down about the center of rotation by dragging as well as move the center, potentially with the arrow keys?

[codegen] Incorrect implementation for __sub__ for int/float and __rsub__ in Python

In the generated Python code, __sub__ for int/float and __rsub__ are not correctly implemented.

Take pga3d.py for example, if we add print(E0 - 1) to the end of the main function and run it, it will complain:

Traceback (most recent call last):
  File "python/pga3d.py", line 469, in <module>
    print(E0 - 1)
  File "python/pga3d.py", line 278, in __sub__
    return a.subs(b)
AttributeError: 'PGA3D' object has no attribute 'subs'

The code reads:

    def __sub__(a,b):
        """PGA3D.Sub
        
        Multivector subtraction
        """
        if type(b) in (int, float):
            return a.subs(b)
        res = a.mvec.copy()
        res[0] = a[0]-b[0]
        # ......
        return PGA3D.fromarray(res)
    __rsub__=__sub__

If we have fixed this issue and add print(1 - E0) to the end of the main function and run it, it will print:

-1 + 1e0

which is obvious the negative of the correct result due to __rsub__=__sub__, as reported by https://discourse.bivector.net/t/bug-in-autogenerated-python-code/49 .

One simple solution is to completely remove the support for multivector/scalar subtraction and vice versa, but this breaks the symmetry of arithmetic and is not preferred.

draw line between point pairs

would it make sense to allow for point pairs to have a line connecting them? maybe this would be a good way to draw vectors?

G41, specify the position of a "plan element" in rendering a plane

Is it possible to specify plane element position in visualizing a plane in ganja.js?

In my toy example, I noticed that two dual planes are placed/centered along the x-axis.

var dual_plane1 = p1 << (1e1 * ni);
var dual_plane2 = p2 << (1e1 * ni);

I assume this is a preference of ganja.js.
Is it possible to let the representation centered at p1 and p2?

Cheers,
Hongying

P.S. In my problem, I'm trying to reconstruct plane elements along a curve, so the position matters. Recommendations of other approaches?

Feature request : OPNS based rendering.

Examine feasibility and implementation options (isosurfaces / marching cubes / depthfield rendering / splatting) for rendering high dimensional objects solely by their OPNS. (request by @darkshikamo / Vincent Nozick)

G41, extract direction vector from a line; extract bivector from a plane

Do we already have formulas in ganja.js / CGA for extracting a vector/bivector from a line/plane?

Aflter closely looking at the basis, I'm doing in the following way now. The results seems reasonable.

But is this approach appropriate?

  var cga_line_2_g3_dir_vector = (cga_line) => 1e145 << cga_line * 1e1 + 1e245 << cga_line * 1e2 + 1e345 << cga_line * 1e3;
  var cga_plane_2_g3_bivector = (cga_plane) => 1e1245 << cga_plane * 1e12 + 1e2345 << cga_plane * 1e23 + 1e1345 << cga_plane * 1e13;

Best,
Hongying

P.S. here is a minimal example: https://observablehq.com/@ying17zi/g3-vector-bivector-extraction-from-a-g41-line-plan-represen

chain rule example?

Do you have any examples of using the chain rule, for (automatic) differentiation?

CGA2D SVG renderer struggles with large circles

I think this is caused by a chrome rendering bug, but it would be good to render sufficiently large circles as lines - the red checkerboard here is apparently a circle.

image

The underlying svg is a <circle> tag with a criminally large radius.

Syntax errors when parsing 'inline functions'

Hey! The 'inline function' parsing causes some syntax errors, that are notably unsemantic and make debugging a bit weird sometimes. I collected a few below :)

  1. Something to do with comments
CGA3D.inline(() => {
  return [
    1, // syntax error
    -2,
  ];
})()
CGA3D.inline(() => {
  return [
    1, // no syntax error
    (-2),
  ];
})()
  1. Element/array access
CGA3D.inline(() => {
  1e5[0]*1e1; // syntax error
})()
CGA3D.inline(() => {
  (1e5[0])*1e1; // no syntax error
})()
  1. Variables
CGA3D.inline(() => {
  const a = 5;
  a[0]*1e1; // syntax error
})()
CGA3D.inline(() => {
  const a = 5e0;
  a[0]*1e1; // no error
})()

Binary tree representations?

Okay first of all I'm really impressed by your work here... It's inspiring! I have lots of questions but will try to focus on one at a time, starting with this one:

How does your approach compare to the recent binary tree approaches described by Théry & Fuchs here and refined by Ahmad Hosny Eid here?

I noticed that ganja.js allows someone to use a generic Cayley table, so maybe it'd be a pretty complicated project to adopt the binary tree approach in ganja.js.

I'm impressed that your generator can handle that wonderful 15 dimensional Quadric Conformal Geometric Algebra. I've created my own algebraic code generation tools in Python with Sympy, but they rely on symbolic algebra libraries that aren't optimized for lots of dimensions. So that very nice Quadric Conformal Geometric Algebra has been off limits!

Bonus question: do you write the code by hand, or do you use some kind of compiler? It's very "concise"!

Crash if using (3, 1, 0) algebra

This fails with Uncaught TypeError: Cannot read property 'Wedge' of undefined.

This happens because ninf and n0 are defined conditionally on the use of g3c, and are not also added for g2c.

Potential improvements for the templated source generator

This is more of a meta issue to track some ideas the came to me during writing the template for Rust:

  • Generate more idiomatic code
  • Generate code for more languages
    • Julia
  • More flexibility for code generator
    • Code organization
    • External dependency
  • Allowing reuse of generated algebra code as libraries
    • Optional main()?
    • Name conflicts of types, constants and free functions?
  • Supports compiling only one language or some languages (for users with only dev environment for some of these languages) #44
  • Add codegen to CI
  • Add tests to verify the correctness
    • Option 1: by checking the outputs of examples
    • Option 2: by generating unit tests
  • Add benchmark to identify performance issues

"vanishing point" of a line

Coming from observable, particularly from having seen your Introduction to PGA. (Amazing work, by the way! I'm new to all this, and hope to get a better grip to make things on my own.) One issue with the graphics that looks weird to me is that the line sweeping by should "vanish at the horizon". I haven't tested it out or digged into the code, but I'm guessing you just draw an (infinite) line on the canvas without considering the perspective.

(If you do make the change, you might want to have the line "fade off", instead of abruptly ending at the horizon. I'm only imagining all this, not having seen any actual implementation myself.)

F-Droid

F-Droid maintainer here. You've asked us to include your app with our repository. We're still stuck with that, waiting for you to include the Cordova project folder (we cannot build Cordova apps without that). Any chance for that?

3DCGA examples

Hi @enkimute I am currrently playing around with different javascript GA libraries as I am keen to write a javascript only replacement for my GAOnline project
gaonline.azurewebsites.net
https://github.com/hugohadfield/GAonline
I really like the look of your project but can't seem to find any examples of 3d plotting with 3dcga, any chance you could point me in the right direction?

Ability to load and save local files for rendering

The ability to upload local files of multivectors into the coffeeshop, ideally of the form discussed in pygae/clifford#61, and, additionally to be able to save the same files, would be fantastic and would aid with easy embedding of ganja into desktop apps and offline sharing of visualisations.

scalars in the regressive product

It seems that there is a bug with the way scalars are handled in the regressive product for dual numbers, in this case Algebra(0,0,1) in ganja cheatsheet

(1+2e0) & (3+4e0) = 10+8e0
1 & (3+4e0) = 4
1 & 3 = 3
1 & 4e0 = 4
2e0 & (3+4e0) = 6+8e0
2e0 & 3 = 0
2e0 & 4e0 = 8e0

Naive question on dev: a minimal example with Ace and Ganja?

Thank you for make such great lib, and congratulate that you obtained the Best Paper Award at ENGAGE 2019.

I'm wondering what's your working environment/workflow?
Do you have a minimal working example with Ace and Ganja enabled?

Thanks,
Hongying

P.S. My clone of your coffeeshop does not update on modification and the GA code does not appear. If I click "new", paste example code there, and click "run", the result rendering part does not update either. (The individual examples render correctly; and the result in web browser updates on modification that occurs in external text editor.)

I'm switching to Ganja for geometric analysis, but have never touched web development.
I figured out that you are using Ace (https://github.com/ajaxorg/ace).
I tried to minimize coffeeshop page and also to tweak examples provided by Ace to obtain a working environment. But progress slowly :(.

Code generator fails to generate for R666 and similar

Code generator fails to generate for R666 and similar, the error is:

make GEN_LANG="python" R666
CUSTOM METRIC :  6 6 6
~/ganja.js:542
      static lt(a,b)  { while(a.call)a=a(); while(b.call)b=b(); return (a instanceof Element?a.Length:a)<(b instanceof Element?b.Length:b); }
                                ^

TypeError: Cannot read property 'call' of undefined
    at Function.lt (~/ganja.js:542:33)
    at x.map (eval at inline (~/ganja.js:1256:16), <anonymous>:3:223)
    at Array.map (<anonymous>)
    at eval (eval at inline (~/ganja.js:1256:16), <anonymous>:3:102)
    at unops.map.u (~/ganja.js/codegen/generate.js:145:25)
    at Array.map (<anonymous>)
    at lang.filter.forEach.lang (~/ganja.js/codegen/generate.js:139:26)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (~/ganja.js/codegen/generate.js:125:35)
    at Module._compile (internal/modules/cjs/loader.js:721:30)
make: *** [makefile:12: R666] Error 1

"viewof" variables in ganja inline functions

This is nor a bug nor a pure ganja.js issue but, in an observable notebook, how do we get access to a "viewof" declared variable in a " CGA.inline((f)=>{ ... })(f) " construction ?

How to change the x/y extent and center the camera of an X, Y plane

Apologies for this basic question. I recently used Ganja in this notebook and it was great! I tried passing in an object to control the camera position without any success.

Could you modify this code below so that the camera is centered at the origin and the zoom is higher?

P2`this.graph(()=>{
  var z = ${v1}
  var pm = ${pp.selection.data}

  var p=(x,y)=>1e12-(x-1)*1.8*1e02-(y-1)*1.8*1e01;

  var a=p(0,0), b=p(z[0],z[1])
  var c=p(1.5,1), p=p(pm[0], pm[1])

  return [,(1+.9e01)>>>1e1,"y",(1-.9e02)>>>1e2,"x",
          0x44AA44,[a,b],0,[a,b],a,"0,0",b,"b",
          0x44AA44,[a,c],0,[a,c],a,"0,0",c,"a",
          0x44AA44,[a,p],0,[a,p],a,"0,0",p,"p",
          0xfdb3b3,[b,p]
  ]}, { // adding the object here with xpos,ypos etc did not seem to work. })`;

TypeError: t is undefined

While attempting to play around with 3dcga I get a strange type error buried deep in ganga which I am struggling to debug:

TypeError: t is undefined[Learn More]
translate
file:///home/hugo/phd/ganja.js/ganja.js:422:196
translate
file:///home/hugo/phd/ganja.js/ganja.js:427:203
inline
file:///home/hugo/phd/ganja.js/ganja.js:479:100
Algebra
file:///home/hugo/phd/ganja.js/ganja.js:521:40

file:///home/hugo/phd/ganja.js/examples/cga3d.html:16:14

Here is my script:
https://gist.github.com/hugohadfield/ad14fdf02bcf22e2e3eec897a405bb2e
any help with this would be immensely appreciated as the stack trace I get is very hard to decipher for a javascript newbie like myself!

Inline functions: scoping, and name

I really love the "inline functions": instead of a complete DSL, or dealing with a clunky javascript API, you just add operator overloading to otherwise normal javascript code by a clever preprocessing step acting by inflection on the function's defining string. Nice :) This does bring an unintuitive problem though: it breaks lexical scoping:

const a = 5;
console.log(CGA3D.inline(() => {
  return a; // nope
})());

A way to deal with this, though a bit cumbersome, is:

const api = { a: 5 };
console.log(CGA3D.inline((api) => {
  return api.a; // OK
})(api));

...but might there be a way to reconcile "inline functions" with lexical scoping?

Also, but less important, I'm not sure if "inline functions" is the most logical naming for this feature. What is its rationale?

Feature request: Camera position + rotation querying

I'm trying to draw the camera position + rotation + scale and the orbit center in the CGA visualiser but can't work out a nice way of querying the camera... does this functionality exist? If not would it be difficult to create? I had a dig into the javascript but couldn't work out how to access the M matrix!

The game goes not work well on Microsoft Edge

It works fine on chrome, though.

I know it's not a big deal but hey it's worth telling.

Great project, BTW! 🥇

If you have time, consider looking at my own experiments with GA : Clifford (Perl 6) and most recently Clifford.js (javascript).

It's not as advanced as yours, but there may be ideas you could use, like how I used a modified version of the PEGJS javascript example grammar to parse the input.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.