On Friday, 5 May 2017 03:59:48 UTC-4, Rupert Smith wrote: > > On Thursday, May 4, 2017 at 5:53:36 PM UTC+1, Matthieu Pizenberg wrote: >> >> I definitely recommend looking at https://github.com/opensolid/geometry >> (with it's svg counterpart : https://github.com/opensolid/svg). >> I've been using it a bit and it's awesome for what I understand you want. >> > > This is nice and quite fully featured. >
Thanks! > It seems a shame that it is not Matrix based though. For example suppose I > want to do a rotation of a shape, ultimately this comes down to mapping > this vector rotation function over all points defining the shape: > > rotateBy : Float -> Vector2d -> Vector2d > rotateBy angle = > let > cosine = > cos angle > > sine = > sin angle > in > \(Vector2d ( x, y )) -> > Vector2d ( x * cosine - y * sine, y * cosine + x * sine ) > > Which means calculating sin and cos again for the same input values for > each point. > Actually, that implementation is designed specifically to avoid recalculating sin and cos values. For example, calling Vector2d.rotateBy someAngle will compute sin and cos values, then return a lambda that captures those computed values so they don't have to be recomputed every time the lambda is called. As a result, things like List.map (Vector2d.rotateBy someAngle) myListOfVectors will only result in sin and cos values being calculated once (I've tested this with Debug.log calls). (Also, fine point: OpenSolid distinguishes between points and vectors, so the rotateBy function above can only be applied to Vector2d values, not Point2d ones.) > If it was Matrix based, you'd calculate the rotation matrix once and then > do just the matrix multiplication part for each point. Due to the > properties of linear algebra, you can combine transformation matrices by > multiplying them all together to capture a more complex transformation in a > single operation. > The equivalent in OpenSolid is to apply a series of transformations to a Frame2d <http://package.elm-lang.org/packages/opensolid/geometry/latest/OpenSolid-Frame2d> or Frame3d <http://package.elm-lang.org/packages/opensolid/geometry/latest/OpenSolid-Frame3d>, then use Point2d.placeIn frame <http://package.elm-lang.org/packages/opensolid/geometry/latest/OpenSolid-Point2d#placeIn> or Point3d.placeIn frame <http://package.elm-lang.org/packages/opensolid/geometry/latest/OpenSolid-Point3d#placeIn> for each point you care about. Building up a transformed frame by applying multiple transformations to it is equivalent to building a combined transformation matrix by multiplication, and calling placeIn is equivalent to using the final transformation matrix to transform the point, but I think every individual step is easier to reason about geometrically (you can visualize moving and rotating frames around, and 'placing' a point inside a given reference frame). I've explained all this in more detail in a reply to a GitHub issue <https://github.com/opensolid/geometry/issues/14#issuecomment-282021044>. > So, nice library with lots of features, missed chance to work with a > better abstraction. > Ouch =) I've done lots of work with matrix-based libraries, and I've personally found matrices (and related stuff like quaternions) very powerful and flexible but also confusion- and error-prone. The OpenSolid libraries are my attempt to provide a better, more geometrically meaningful abstraction that still allows you to get good performance. For what it's worth, I'm just finishing up a small package to allow interop between OpenSolid and elm-community/linear-algebra - so if you want to you'll be able to transform OpenSolid points and vectors using a Mat4. -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
