2

Suppose I have two definitions of a function such as

arrowAxesXYZ[{a_, b_, c_}] := 
 Map[Arrow[Tube[{{0, 0, 0}, #}]] &, {a + 2, b + 2, 
    c + 2} IdentityMatrix[3]]

arrowAxesXYZ[{a_, b_, c_}, arrowhead_, arrowstyle_] := {arrowstyle, 
  Arrowheads[arrowhead], 
  Map[Arrow[Tube[{{0, 0, 0}, #}]] &, {a + 2, b + 2, 
     c + 2} IdentityMatrix[3]]}

Graphics3D@arrowAxesXYZ[{10, 3, 2}, Large, Red]
Graphics3D@arrowAxesXYZ[{10, 3, 2}]

enter image description here

The first function arrowAxesXYZ[{a, b, c}] uses the default values Arroheads and style of the Arrow. The second one arrowAxesXYZ[{a, b, c}, arrowhead, arrowstyle] uses the values given by the user.

How can I compine the two definitions into one? I am familiar with Default but I don't know how it can be used here.

Thanks.

Karsten7
  • 27,448
  • 5
  • 73
  • 134
Dimitris
  • 4,794
  • 22
  • 50
  • 2
    http://reference.wolfram.com/language/tutorial/SettingUpFunctionsWithOptionalArguments.html and http://reference.wolfram.com/language/tutorial/OptionalAndDefaultArguments.html. – Karsten7 Nov 20 '15 at 15:51
  • 1
    Possible duplicates: http://mathematica.stackexchange.com/questions/353/functions-with-options, http://mathematica.stackexchange.com/questions/1567/how-can-i-create-a-function-with-optional-arguments-and-options – Karsten7 Nov 20 '15 at 15:58
  • 1
    @dimitris: Why do you need to combine the two definitions into one? – murray Nov 20 '15 at 16:44
  • I thought it was a good idea than having two separate definitions. – Dimitris Nov 20 '15 at 16:49

1 Answers1

2
Clear@arrowAxesXYZ

arrowAxesXYZ[{a_, b_, c_}, arrowhead_: Automatic, arrowstyle_: {}] :=
 {arrowstyle, Arrowheads[arrowhead],
  Map[Arrow[Tube[{{0, 0, 0}, #}]] &, {a + 2, b + 2, c + 2} IdentityMatrix[3]]}

Graphics3D @ arrowAxesXYZ[{10, 3, 2}, Large, Red]

enter image description here

Graphics3D @ arrowAxesXYZ[{10, 3, 2}]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168