I am creating a web-service which is aimed to simulate how do electronic circuits work. The project is not even in the Alpha stage yet.
I am stuck with some important milestone of the project: when one tries to connect one component's pin to some other pin - the connection line should be built.
First of all, the connection line was just a straight line, without almost any way to change it.
Then it became somehow bended line with the possibility to add, move and delete points, which determined how the line is bended.
And now it (connection line) is created using the A* algorithm.
The implementation is not well yet, so editing A*-generated connection line is not a good idea, 'cause it fails a lot.
The idea for the connection line creation algorithm is just as follows:
determine start and end points
find a path between start and end, which does not overlap any existing component' bounding box
create a set of base points - a list of coordinates, got from the step #2 + start at the heap + end at the tail
create a set of lines which will form a connection line:
for (var i = 1; i < points.length; i++) { var p0 = points[i - 1], p1 = points[i], line = MooChip.paper.path(Raphael.format('M%1,%2L%3,%4', p0.x, p0.y, p1.x, p1.y)); }
The problem is that connection lines could overlap, while they must intersect only... Well, actually there is another problem: i could not even imagine how one could implement connection lines connection, like here, the bottom-left image:
The question is: how should i build the connection path (to make it mostly close to the well-designed circuit diagram, let's say) and how can i implement schematic junctions?
Firstly, at this moment i can't give whole solutions, but maybe it will help:
- check graphflow project, its javascript canvas view builds the graph and aligns it based on connections as i see. That is exactly what is needed for circuits (f.e. GND sign will be vertex with only one connection, so will be drawn at the boundary region of schema)
- that approach should be modified somehow with putting it to grid and making all connections orthogonal
- about "connection path" it is just one more element and should be aligned as others. It is like transistor, but too small to see all three connectors
来源:https://stackoverflow.com/questions/10296758/electronic-circuit-diagram-component-connection-algorithm