Circuit schematic wire layout algo?

Blitz3D Forums/Blitz3D Programming/Circuit schematic wire layout algo?

octothorpe(Posted 2006) [#1]
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.




WolRon(Posted 2006) [#2]
Haven't checked out your code (mostly due to not bothering to download the include file), but wouldn't laying out all of your components on some sort of grid help to determine where you can/can't lay down circuit connections?


Dreamora(Posted 2006) [#3]
You might check google or more programming related pages for "scan line algorithms" which are what normally is used on geometric problems to find a solution. They are suited especially for your situation where you are looking for wire layout.


big10p(Posted 2006) [#4]
Not sure exactly what you want, but doesn't this just boil down to 2D pathfinding? Would a modified A* algo do the job?