Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to draw a set of lines in mathematica all with the same origin point?

I have a set of points given by this list:

list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};

I would like Mathematica to draw a line from the origin to all the points above. In other words draw vectors from the origin (0,0) to all the individual points in the above set. Is there a way to do this? So far I've tried the Filling option, PlotPoints and VectorPlot but they don't seem to be able to do what I want.

like image 837
franklin Avatar asked Dec 03 '22 01:12

franklin


2 Answers

Starting easy, and then increasing difficulty:

Graphics[{Arrow[{{0, 0}, #}] & /@ list1}]

enter image description here

Graphics[{Arrow[{{0, 0}, #}] & /@ list1}, Axes -> True]

enter image description here

Needs["PlotLegends`"];
list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};
k = ColorData[22, "ColorList"][[;; Length@list1]];

GraphicsRow[{
    Graphics[Riffle[k, Arrow[{{0, 0}, #}] & /@ #], Axes -> True], 
    Graphics@Legend[Table[{k[[i]], #[[i]]}, {i, Length@#}]]}] &@list1

enter image description here

Needs["PlotLegends`"];
list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};
k = ColorData[22, "ColorList"][[;; Length@list1]];
ls = Sequence[Thick, Line[{{0, 0}, {1, 0}}]];

GraphicsRow[{
    Graphics[Riffle[k, Arrow[{{0, 0}, #}] & /@ #], Axes -> True], 
    Graphics@Legend[MapThread[{Graphics[{#1, ls}], #2} &, {k, #}]]}] &@list1

enter image description here

Needs["PlotLegends`"];
list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};
pr = {Min@#, Max@#} & /@ Transpose@list1;
k = ColorData[22, "ColorList"][[;; Length@list1]];

GraphicsRow[{
    Graphics[r = Riffle[k, {Thick,Arrow[{{0, 0}, #}]} & /@ #], Axes -> True], 
    Graphics@
     Legend[MapThread[
             {Graphics[#1, Axes -> True, Ticks -> None, PlotRange -> pr], 
              Text@Style[#2, 20]} &, 
             {Partition[r, 2], #}]]}] &@list1

enter image description here

You could also tweak ListVectorPlot, although I don't see why you should do it, as it is not intended to use like this:

list1 = {{3, 1}, {1, 3}, {-1, 2}, {-1, -1}, {1, -2}};
data = Table[{i/2, -i/Norm[i]}, {i, list1}];
ListVectorPlot[data, VectorPoints -> All, 
                     VectorScale  -> {1, 1, Norm[{#1, #2}] &}, 
                     VectorStyle  -> {Arrowheads[{-.05, 0}]}]

enter image description here

like image 80
15 revs Avatar answered Dec 20 '22 02:12

15 revs


Graphics[
 {
  Line[{{0, 0}, #}] & /@ list1
  }
 ]

enter image description here

where /@ is the shorthand infix notation for the function Map.

I wonder why you tried Filling, Plotpoints and VectorPlot. I must assume you haven't read the documentation at all, because even a superficial reading would tell you that those commands and options have nothing to do with the functionality you're looking for.

like image 22
Sjoerd C. de Vries Avatar answered Dec 20 '22 00:12

Sjoerd C. de Vries