I'm making a digital logic simulator just for fun and my wires are currently single quads stretched between the contact points of my components. In good circuit schematics, wires are usually composed of several segments, drawn horizontally and vertically, and (most importantly) do not overlap components.
Does anyone know of an algorithm (or any ideas at all) I can use to determine how to lay out my wires between arbitrarily positioned contact points on arbitrarily positioned components? I'm thinking a function which uses trial-and-error checking for collisions with components, then returns a list of x,y coordinates for the coords of the segments that will make up a wire.
Here are some examples of some rather tricky circuit schematics: http://images.google.com/images?q=jk%20flip%20flop
And here is my work-in-progress simulator. Right-click the "switches" on the left to toggle their state and watch the gates flip their logic states. You can add and remove wires by left clicking and move components by left dragging. To change the gates you're playing with, you'll need to modify the top of the program (create_component() calls) - feel free to remove all the code responsible for adding wires (create_wire() calls) in the initialization: you can add wires while you're running the program. The circuit depicted is a JK Flip Flop: a single bit of memory composed of four NAND gates.
|