Graphics Tools for Circuits

I am sharing a program for creating circuit diagrams. The share location is: http://cit.blinn.edu/Physics/Mathematica/

Circuit components examples are shown below.

The basic syntax is:

Graphics[
 DrawCircuit[<|"a" -> {0, 0}, "b" -> {1, 0}|>,
  {{{"a", "b"}, {Inductor["L"], Capacitor["C"]}}}, {{"a", 
    Node["a", TextOffset -> .75]}, {"b", 
    Node["b", TextOffset -> .75]}}, TextOffsetScale -> .75], 
 BaseStyle -> {12, Italic, FontFamily -> "Times"}]

with the output.

LC.gif

Here is a more complex example with code.

With[{a = .5, colV = RGBColor[.3, .3, .9], 
  colA = RGBColor[.9, .1, .1]},
 Graphics[{DrawCircuit[
    {{0, -a}, {3, -a}, {0, 0}, {1, 0}, {2, 0}, {3, 
      0}, {1, -a}, {2, -a}},
    {
     {{7, 
       8}, {ACVoltage["\!\(\*SubscriptBox[\(V\), \(rms\)]\), \!\(\*
StyleBox[\"f\",\nFontSlant->\"Italic\"]\)", 
        TextOffset -> 1.25]}}, {{1, 7}, {}}, {{2, 
       8}, {InlineMeter[Style["A", 14, Italic, colA], 
        InlineMeterDirectives -> colA]}},
     {{1, 3}, {}}, {{2, 6}, {}},
     {{3, 4}, {Resistor[Style["R", Italic], TextOffset -> -1]}},
     {{4, 5}, {Inductor[Style["L", Italic], TextOffset -> -1]}},
     {{5, 
       6}, {Capacitor[Style["C", Italic], 
        TextOffset -> {0, -1.625}]}}, {OffsetPoints[{3, 
        5}, .125, .625, 
       WireDirectives -> colV], {InlineMeter[
        Style["\!\(\*SubscriptBox[\(V\), \(R, L\)]\)", 14, colV], 
        InlineMeterDirectives -> colV]}},
     {OffsetPoints[{5, 6}, .265, .625, 
       WireDirectives -> colV], {InlineMeter[
        Style["\!\(\*SubscriptBox[\(V\), \(C\)]\)", 14, colV], 
        InlineMeterDirectives -> colV]}},
     {OffsetPoints[{3, 6}, .1, 1.125, 
       WireDirectives -> colV], {InlineMeter[
        Style["V", 14, Italic, colV], 
        InlineMeterDirectives -> colV]}}
     }
    ]
   }, BaseStyle -> {12, FontFamily -> "Times"}]]

12 Likes

Looks quite interesting. One caveat: it seems to very much dislike version 9 of Mathematica, at least on Ubuntu Linux. I had considerable difficulty scrolling, selecting cells, etc. Since it uses Association, if I saw correctly, this is strictly for version 10.

3 Likes

The data for node positions is represented in terms of Associations, so this only works with version 10. In earlier versions I represented the node data differently, but this struck me as a natural and appropriate place to use this new data structure. I am attaching an old version that should work with version 9. It is a .nb file with initialization cells that will generate a package when saved.

4 Likes

This is great! Very nice use of Associations. If I understood correctly the circuit layout is manual by coordinate specification. Are you aware of any algorithms that layout circuits automatically? Perhaps using Graph somehow with GraphLayout → “GridEmbedding” or similar this could be solved?

2 Likes

There are already a few posts on the community related with graph kind of GUI building. Some functionalities slightly overlap what a Modelica environment was built for, but others are used on completely different concepts. We know that building an efficient drag and drop interface, with snaps,etc, is currently not viable in Mathematica.

Can someone from WRI tell if this kind of interface object is being considered for future versions of Mathematica? It would greatly extend the GUI capabilities of Mathematica, and make the posted circuit tool viable to a much wider audience.

(by the way… great tool. Thank you)

1 Like

Great!

I saw also other useful packages, such as units.

Looks very neat!

You could post this as an answer here (answers can even be posted without registering, though registration has its benefits…)

You might also be interested in the other answers there. Others have been working on circuit drawing mini-languages too.

Perhaps this could be incorporated in Graphplot ?