Enter The Matrix

One AU evening at the bar, I was chatting to a couple of developers who suggested covering some fundamental mathematics on this blog: their respective career paths had not involved any formal (or perhaps recent) studies of certain important areas of mathematics, especially related to core linear algebra concepts such as matrix multiplication.

Part of me said, "what a great idea", another part said "I wonder what resources are already out there" and the last said "oh man, I don't remember how all that stuff actually works". 🙂

Before I start dusting off some of that well-buried geometrical knowledge, I thought I'd ask a couple of questions of this blog's readership:

  1. Does this sound like a useful topic to anyone else?
  2. For those who have had to work through such topics in recent (enough) memory, do you recommend any particular resources to use? (If there's something out there that serves the purpose well – even if it doesn't address the concepts with respect to AutoCAD's geometry library – that would save some trouble.)

Please post a comment if you have anything to share on this topic.

  1. 1. Yes!

  2. For example,
    If you load a lisp that should make something slow in your file, it would be interesting to have a progress bar to indicate it as of the task it was already accomplished.
    We don't sometimes know if AutoCAD crashed (FATAL ERROR) or if it is still executing the lisp.

  3. I think that sounds like a very good idea. But, please make sure you do tie in the mathematical concepts with AutoCad's geometry library (as you already mentioned). In other words, show how the theory is applied in practice. Looking forward to reading what you come up with.

  4. I don't know if here it would be the correct place, then forgive me if I did wrong.

  5. Agreed! I don't have any formal training in linear algebra, having only gone to a tech school for CAD, and I don't remeber getting into any complex mathematics. All the .net programming I've learned after the move away from vba in autocad, so learning how to do anything in .net was learned through blood, sweat, and tears! And I'm sure I'm not the only one in this boat B)

  6. Oh god, what would I have been thankful for such a source in 2004, when I had to implement a vector and matrice library in VisualLISP...

  7. A quick google turns up this as a potentially useful resource - 1 But I've not looked very hard at it.

    Wikipedia may err on the side of being a little too academic - 1

  8. Kean

    Your blog is great at giving examples of using limited or undocumented areas of the Autcad API to achieve practical tools. Maybe not the place to go into maths theory. I have used this great little site as a reference before on Linear Algebra
    softsurfer.com/
    in a previous life programming in c++ with a different cad package cadmethods.com/products6.htm

    Regards

    Justin Ralston
    c3dxtreme.blogspot.com/

  9. I forget everything mathematical immediately after use, and I find it all again the next time I need it in wikipedia, just like the examples you give above. Google always answers every question I have, and mostly provides source ready for immediate use to boot...

  10. I am in favor of this idea. There is no such thing as too much math knowledge--besides, it is so much fun! Perhaps the linear algebra could be interspersed with your usual style of projects.

  11. Hi Luciana,

    See and download a great set of free LISP tools, including a progress bar implementation, at wiki.mcneel.com\developer\doslib

    -Brad

  12. Kean,
    All hail the omnipotent transformation matrix! Scale, rotate 3D, mirror, move - all could be accomplished if we just knew how to implement one in .NET
    Brad

  13. John Holmes; ADN #3908 Avatar
    John Holmes; ADN #3908

    YES! YES!
    Cover the basics using common problems. Things like :

    -Various ways to project points. Using a matrix, vectors, trig. All have an appropriate time and place. One must select the correct representation based on what AutoCAD expects. So understanding how and when to select a representation is the very basis to understanding the AutoCAD math library.

    -Basic solutions to common problems like: Is a point inside a polyline? Is one polyline contained within another? Completely? By how much?

    -How do we “Look” using math? If I have an object, how do I “Look” around to see what’s near it?

    -Understanding how to move geometry from one space to another. For instance; If I want to see if a line in the current drawing intersects with a line in an xref (that may be scales or drawing in other units)

    -In the same vein, comparing objects to objects contained in blocks. Perhaps by building abstract versions of each block for fast compares.

    -All of the “Select” commands work using the video buffer. How would you implement the math to compare against all the different types? What I mean is; what base class(s) do you select and when?

    We can use this as an excuse to build a “Poor” mans AutoCAD math library.

  14. Kean

    Great idea - go for it. General matrix calcs would be useful to a lot of people I think and especially ones that involve coordinate systems OTHER than WCS which are historically the ones most forget to implement.

  15. The comments raised so far speaks volumes about the interest in this topic. There is nothing for me to say that has not been said. But still posting this just to increment the (reference 😉 ) count.

  16. Definately.
    I often times find myself relying heavily on the methods of the AutoCAD objects to perform the operations I need, but as usual, I always end up needing something that isn't built-in.
    Even as a computer science major in college, I don't ever remember doing any matrix math. Most of my knowlege of vectors was learned in a physics classroom.
    Good resources are hard to find. I often spend quite a bit of time looking on the internet just to find an article I can understand or at least directly apply to what I'm doing.

  17. Anything math is okay with me.

  18. It's like you read my mind. I was just wishing for someone to explain matrixes and how AutoCAD uses them. This would be fantastic!
    I've been bugged by the way attributes behave (or don't) when I work with blocks in .NET. They seem to get disoriented.

    My friend looked up information on matrixes but it was over his head. Please explain it so my friend who only understands basic geometry could understand it. He likes pictures.
    Ok, there is no friend, it's me. I don't understand matrixes.

  19. Could someday AutoCAD incorporate all computational geometry theory such as Voronoi diagram,Delauney triangulation,etc, like what Matlab did?

  20. Constantin Gherasim Avatar
    Constantin Gherasim

    Hi Kean,

    I would say that although there is indeed a lot of information on this topic on the Internet, it is always treated and explained in a very general manner and I think that a more applied approach, explaining how all this abstract information concretely applies to AutoCAD entities and APIs (starting with AutoLISP), would be more than welcome.

    Thanks in advance,

  21. I say Yes. There is always a need to refresh or relearn. But I will also put in my vote for a .Net (C# prefered) example when showing how it relates to autoCAD.

  22. Kean,

    Sounds like a great resource ... go for it !

    Regards,

  23. Kean,

    Sounds like you got a ringer.
    -Shaan

  24. Kean,

    Thanks for the question. My issue, like a couple other commenters here, is that I last took math more than 20 years ago, and it wasn't in a programming context. I'm an architect by training, so I'm more visual anyway. I don't understand how to solve many 2D geometry programming problems, much less the 3D that's required these days.

    I recently had a geometry question for an AutoCAD app that should be relatively simple for math wizards, diagrammed here: mathworld.wolfram.com/Circle-CircleTangents.html. I simply needed to solve for the various tangent points given the two circles. And, I needed to do it with code. So, even if I understood the math involved, translating that to .NET was more than I could handle. Many Google searches turned up nothing that I could use or could translate, and perhaps I wasn't even sure what to search for (Circle Circle Tangent, Serpentine pulleys, timing belts, etc).

    I was thinking at the time that it would be great if there were a community site where people would post diagrams like this, and beneath it would be .NET or AutoCAD code that would solve for the various X,Y,Z points (or other variables). I think that if you look at the breadth of information on the mathworld site, you're looking at potentially a ton of blog posts, so I would suggest a separate site of some sort.

    BTW, if anyone can 'teach me to fish' on this particular problem, I would really appreciate some references.

    Great to see you at AU, and thanks again for the blog!

    -Danny

  25. Great to see you, too, Danny. 🙂

    This is a level of complexity that I would expect AutoCAD to handle: in this case applying tangential constraints between the circles and the lines, rather than making the calculations manually.

    Kean

  26. Hi,
    i think there is a point not mentioned yet...

    It is very useful and important to be able to tap (or hook)
    directly into the "mathematics"(equations) underlying a CAD-object like a curve (3Dspline) or surface (NURBS or analytic) in order to programmatically calculate "things" like Torsion, Carvature, Local and Global Minimas and Maximas needing the third derivative of the the curve of Surface at a given Point or some other higher analytic maths.

    The API'S expose Properties and Methods of Objects but not their underlying mathematics, the parametric equations for example of a Curve or Surface!

    So I would suggest to think in this Direction and expose directly the mathematical equations of certain Objects either by providing the necessary API Methods or interactively through AutoCAD Commands.

    The implementation let say of a sort of "reverse engineering" of the object mathematics would be very useful for Generative or Parametric Modeling or even to explore the mathematics of a NURBS Surface or a SPLINE in 3D Space (WKS or UCS)

    So imagine to select a Curve or Surface on the Screen and
    obtain its mathematical Equation in parametric, explicit or Implicit Form..!!!???

    The forthcoming DesignScript programming language for AutoCAD and possibly other Autodesk Products(AU 2010 ?) would benefit from such a paradigm of CAD-mathematics-exposure.

    Linear Algebra and Matrix Maths for geometry transformations are important but equally important is a mathematical exposure of the underlying structure or equations of CAD objects where desirable and appropriate.

    Many Thanks to all for the useful ideas and websites

    Konstantin

  27. Danny Polkinhorn Avatar

    Fair enough. In this case however, I was attempting a DrawableOverrule and I didn't have the luxury of using constraints. I also needed to remove all the internal geometry inside the circles and between the external tangent lines, leaving only arc segments at the ends and the tangent lines. If we expand my example beyond AutoCAD to other Autodesk APIs, I also might need to make the calculations manually because of their geometry library limitations. So, this one example may be handled by AutoCAD's internal geometry APIs (if so, I might need code for that too), but the underlying manual calculations might be useful in a variety of applications and contexts. Clearly, I'm suggesting something beyond the scope of what you're looking to do, but a guy can dream a little right? 😉

    Thanks again,
    -Danny

Leave a Reply to Tim Cancel reply

Your email address will not be published. Required fields are marked *