Git Product home page Git Product logo

linear-algebra's Introduction

DEPRECATED: Moved to elm-explorations/linear-algebra

Fast Linear Algebra for Elm

A library for fast vector and matrix math. See the full docs here.

This is needed for 3D rendering with WebGL in Elm, but is useful for anything where fast linear algebra is needed.

It is based on the MJS library for JavaScript.

linear-algebra's People

Contributors

fredcy avatar process-bot avatar johnpmayer avatar nphollon avatar eeue56 avatar w0rm avatar mchav avatar mgold avatar kfish avatar felixlam avatar dandandan avatar despairblue avatar dackerman avatar mkovacs avatar robert-wallis avatar exists-forall avatar

Stargazers

Kevin Xiang Li avatar meriy100 avatar Paul Tan avatar Pandu Ranganth avatar Leonardo Farroco avatar  avatar Hrishikesh Choudhari avatar Jonatan avatar Ulric Wilfred avatar Tomasz Cichocinski avatar Dan Minshew avatar Marc-Olivier Andrez avatar  avatar Matthieu Pizenberg avatar

Watchers

 avatar  avatar  avatar Rehno Lindeque avatar James Cloos avatar Hrishikesh Choudhari avatar  avatar Janis Voigtländer avatar Harry Sarson avatar

linear-algebra's Issues

Use consistent type for native arrays

I noticed that MJS.js defines var MJS_FLOAT_ARRAY_TYPE = Float64Array; while Vector2.js and Vector4.js use var MJS_FLOAT_ARRAY_TYPE = Float32Array;

I don't know if this was intentional or not, but I think this library should use the same type for all.

cc @felixLam

Misses initializer for Matrix4 with all fields

Hi there,

currrently there appears to be no function to create a Matrix4 from 16 fields. I currently need this in order to interact with the pixel matrix of a Mapbox GL js map. In an older version of this package the following was possible:

case matrixAsArray of
    [ m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44 ] ->
        mat4 m11 m12 m13 m14 m21 m22 m23 m24 m31 m32 m33 m34 m41 m42 m43 m44

    _ ->
        Matrix4.identity

Have a missed this function in the current release?

I would appreciate your feedback. I would imagine that it would work well to create a function with the following signature:

{-| Creates a Matrix4 from four Vec4
-}
makeFrom4Vec4 : Vec4 -> Vec4 -> Vec4 -> Vec4 -> Mat4
makeFrom4Vec4 = Native.MJS.m4x4makeBasis

or:

{-| Creates a Matrix4 from a list of elements. If the number of elements
is not exactly 16, this returns Nothing.
-}
makeFromList : List Float ->Maybe  Mat4
makeFromList list = 
    case list of
        [ m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44 ] ->
            Just M4x4.$ pixelMatrix

        _ ->
           Nothing

Vector4 setters produce incorrect results

> myVec4 = V4.vec4 1 2 3 4
{ 0 = 1, 1 = 2, 2 = 3, 3 = 4 } : Math.Vector4.Vec4
> V4.setX 7 myVec4
{ 0 = 0, 1 = 0, 2 = 0, 3 = 0, 4 = 0, 5 = 0, 6 = 0 } : Math.Vector4.Vec4
> V4.setY 7 myVec4
{ 0 = 0 } : Math.Vector4.Vec4
> V4.setZ 7 myVec4
{ 0 = 0 } : Math.Vector4.Vec4
> V4.setW 7 myVec4
{ 0 = 0 } : Math.Vector4.Vec4

Question before making PR

Some background: Last week I have been working to get a ray casting example working for object picking purposes. I ran into an issue that two functions were missing:
Multiplying a Vec3 with a Float

multi : Vec3 -> Float -> Vec3
multi v1 f =
  vec3
    ((Vec3.getX v1) * f)
    ((Vec3.getY v1) * f)
    ((Vec3.getZ v1) * f)

Multiplying a Mat4x4 with a Vec4:


mulVector : Mat4 -> Vec4.Vec4 -> Vec4.Vec4
mulVector mat v =
    let
        rec =
            Mat4.toRecord mat

        r1 =
            Vec4.vec4 rec.m11 rec.m12 rec.m13 rec.m14

        r2 =
            Vec4.vec4 rec.m21 rec.m22 rec.m23 rec.m24

        r3 =
            Vec4.vec4 rec.m31 rec.m32 rec.m33 rec.m34

        r4 =
            Vec4.vec4 rec.m41 rec.m42 rec.m43 rec.m44
    in
        Vec4.vec4 (Vec4.dot r1 v) (Vec4.dot r2 v) (Vec4.dot r3 v) (Vec4.dot r4 v)

As you can see these are elm functions, the rest of the library is using native functions. Are you open to a PR for these? Or should they be converted to native js functions first?

Add pointwise mapping

[2017-03-06: I copied this issue, created by @folkertdev, from https://github.com/elm-community/elm-linear-algebra/issues/18 per https://github.com//issues/7. -fredcy]

As it stands, the types in this library are somewhat tedious to work with. Especially when applying
the same operation to multiple components. @fredcy mentioned on slack that conversion to List/Array is planned, but this still requires two conversions (to and from List/Array).

suggestion

Implement a pointwise map and map2 which are equivalent (in the Vec2 case) to

map : (Float -> Float) -> Vec2 -> Vec2
map f = 
    fromTuple << (\(a, b) -> (f a, f b)) << toTuple

map2 : (Float -> Float -> Float) -> Vec2 -> Vec2 -> Vec2
map2 f a b = 
    let (left, right) = (toRecord a, toRecord b) 
    in 
	fromTuple ( f left.x right.x, f left.y right.y )

edit: implementing map3 in terms of map2 isn't very practical

concrete use case:

-- maximal and minimal components of two vectors 
boundingBox a b = (map2 min a b, map2 max a b) 

points of discussion

  • A logical extension would be to also introduce mapX, mapY, map...
  • pointwise is an alternative name to map2 that reads nicer (but is less consistent)
  • map2 is restricted to functions of type Float -> Float -> Float, where Float -> Float -> a would be more useful. Rather than adding functionality to Vector, a Tuple.Extra package could implement the various mapping functions.

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.