2
$\begingroup$

Here is a simple code I wrote to visualize what I am trying to achieve:
C.1

Labeled[Graph[Range[#], Table[i <-> i + 1, {i, Range[# - 1]}], 
VertexCoordinates -> {{-5, 5}, {5, 5}, {5, -5}, {-5, -5}},
VertexLabels -> "Name"], "Graph Sample v1.0"] &@4

enter image description here
In this code snipet, the vertices and edges are generated semi-automatically for the users convienience. The number &@4, ideally should be replaced by the length of a list containing a set of coordinates defined by the user.

I believe I can achieve this using Length[expr] function which could be fed the user defined set of cooordinates as an input.

In order to achieve what I have described above, I have employed a variation of code such as:
C.2

Labeled[Manipulate[Graphics[{Line[v]}, 
PlotRange -> {-6, 6}], {{v, {{-5, 5}, {5, 5}, {5, -5}, {-5, -5}}}, 
Locator, LocatorAutoCreate -> True}], "Locator Example"]

enter image description here
NOTE
N.1 - I am aware that the code does contain an equal set of coordinates as in my first code snipet above.

However, I was unable to extract the generated list of coordinates which could be used to define VertexCoordinates in a Graph. Additionally inheriting a new problem with the locator requiring an input in a form of coordinates for initialisation..

As the title says, I would appreciate if anyone could give me some pointers or assistance with this problem. I am also considering extending this into three-dimensions and would appreciate any input on that on seperate basis. Many thanks in advance. Hope the question is well rounded and provides enough ground to go by.
-e

$\endgroup$
1
$\begingroup$

You could add button to copy or print coordinates:

Labeled[Manipulate[
  Graphics[{Line[v]}, 
   PlotRange -> {-6, 6}], {{v, {{-5, 5}, {5, 5}, {5, -5}, {-5, -5}}}, 
   Locator, LocatorAutoCreate -> True}, 
  Button["Copy Coordinate", CopyToClipboard[v]], 
  Button["Print Coordinate", Print[v]]], "Locator Example"]

graph with locators

| improve this answer | |
$\endgroup$
  • $\begingroup$ thank you for the time you've spent developing a solution. It is very much appreciated. The solution you have proposed is insightful, it is close to what I am trying to achieve. Ideally, I would like your solution to feed data to VertexCoordinates within a Graph, I have tried several permutations of the solution you have proposed, however failed to achieve my goal. I was wondering if you'd have any ideas on how the above could be achieved. $\endgroup$ – e.doroskevic Aug 17 '15 at 19:22
2
$\begingroup$
g = Graph[{1 <-> 2, 2 <-> 3, 3 <->1}];
init = VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates];
(* Rescale to 10% padding *)
xyScale = 1.1 # -.1 Mean@# &/@ (Through[{Min,Max}[#]] &/@ Transpose@init);

Manipulate[SetProperty[g, {VertexCoordinates -> pt, PlotRange -> xyScale}],
          {{pt, init}, Locator}]  

Mathematica graphics

| improve this answer | |
$\endgroup$
  • $\begingroup$ thank you for your answer, I was wondering if you could expand on it by including an explenation on how it achieves the desired outcome? Please forgive me if it's obvious, it's a bit ambigious to me since I am not very advanced with use of Mathematica. Many thanks for your time in advance. $\endgroup$ – e.doroskevic Aug 15 '15 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.