# Plotting line segments in complex plane

Recent versions of Mathematica have introduced various functions for plotting in terms of complex numbers and complex functions, including ComplexPlot, ComplexListPlot, ComplexRegionPlot, and ComplexVectorPlot. These functions allow direct use of complex numbers and complex functions without the user having to explicitly apply ReIm or otherwise split complex objects into their real and imaginary parts.

Question: Is there a built-in function that provides some very basic and essential plotting functionality for geometric objects specified in terms of complex numbers. For example:

• plotting a line segment in the complex plane by directly specifying its endpoints as complex numbers?
• plotting a circle (not a filled disk!) in the complex plane by specifying its center directly as a complex number and its radius?

(And if not, why on earth not?? Given that Mathematica regards complex numbers as being so fundamental that one must explicitly override assumptions of numbers being complex when you want them to be real, it seems surprising to me that it's taken even this long for Mathematica to build in the complex plotting functions I cite.)

As a very basic and simple example, I want to do make the following kind of graphics — without having to use ReIm to split up explicitly all the complex numbers into their real and complex parts.

Graphics[{Circle[ReIm[2 + 2 I], 1], PointSize[Large], Red,
Point[ReIm[2 + 2 I]], Thick, Blue, Line[ReIm[{1 + 2 I, 3 + 2 I}]]},
Axes -> True, AxesOrigin -> ReIm[0]]


At least ComplexListPlot would allow plotting one element there, namely, the center of the circle, and that could be combined using a Show with the other graphics. Still, that leaves the circle and line segment to treat.

Update 2: We can simply wrap the first argument of Graphics with a function that Replaces Complex[a, b] with {a,b}:

ClearAll[foo]
foo = Replace[#, Complex[a_, b_] :> {a, b}, All] &;

SeedRandom[77]
rc = RandomComplex[1 + I, 6] ;

Graphics[foo @
{Thick, {RandomColor[], Circle[#, RandomReal[{1/10, 1/2}]]} & /@ rc,
Blue, Dashed, Line[Partition[rc, 2, 1]],
PointSize[Large], Gray, Point@rc,
Red, BSplineCurve @ rc,
Opacity[.3, Purple], Rectangle[rc[[1]], rc[[-1]]],
Opacity[.3, Green], Polygon[RandomSample[rc, 4]]}]


Update: We can define primitives with complex coordinates:

ClearAll[complexCircle, complexLine, complexPoint]

complexCircle[cntr_Complex, r_] := Circle[ReIm @ cntr, r]
complexPoint[c_Complex] := Point[ReIm @ c]
complexPoint[c:{__Complex}] := complexPoint /@ c
complexLine[{a_Complex, b_Complex}] := Line[ReIm[{a, b}]]
complexLine[l:{{_Complex, _Complex}..}] := complexLine /@  l


Examples:

SeedRandom[77]
rc = RandomComplex[1 + I, 5] ;
Graphics[{Thick, { RandomColor[], complexCircle[#, RandomReal[{1, 5}]]} & /@ rc,
Blue, Dashed, complexLine[Partition[rc, 2, 1]],
PointSize[Large], Gray, complexPoint @ rc}]


{pnt1, pnt2, pnt3} = {1 + 2 I, 3 + 2 I, 2 + 2 I}


You can use a ComplexContourPlot and ComplexListPlot and combine the outputs using Show:

Show[ComplexContourPlot[Abs[z - pnt3] == 1, {z, 3}] ,
ComplexListPlot[{{pnt1, pnt2}, {pnt3}}, Joined -> {True, False},
PlotStyle -> {Directive[Thick, Blue],  Directive[Red, PointSize[Large]]}],
PlotRange -> All]


• That does the trick. I use the word "trick" advisedly: Surely there should be a simpler, direct way to plot geometric objects in the complex plane. In other words, although the answer gives the graphics result I want, it involves "jumping through hoops." After all, for ordinary graphics using Euclidean coordinates, one simply uses Circle and Line. Surely there should be a ComplexCircle and ComplexLine. One could define a function ComplexCirclePlot to provide the expression you gave for the circle, but that is already an actual plot rather than a graphics primitive. Commented Sep 17, 2020 at 17:05
• @murray, please see the update.
– kglr
Commented Sep 17, 2020 at 17:30
• Yes, those functions in your update take care of things. I still want them, and more, to be built into Mathematica. Perhaps if you contributed them to the Wolfram Function Repository, we'd have a start in getting WRI to take action. (Note: In all this, I'm trying to wean myself from the complex graphics capabilities of David Park's Presentations addon, since he no longer maintains it.) Commented Sep 17, 2020 at 19:08
• The argument patterns in the suggested functions don't suffice to handle arguments such as in complexLine[{2 + 2 I, 2 + 2 I + 1/Sqrt[2] + 1/Sqrt[2] I}], even if in the definition, the appearances of the variables on the right-hand sides are wrapped in N. Any ideas? Commented Sep 17, 2020 at 20:51
• complexCircle[I,1] works as expected, but complexCircle[0,1] does not recognize 0 as a valid complex number, nor does it recognize any real number as being (also) complex. Commented Sep 14, 2023 at 17:18

I just added in some matching coloring of the points and circles, since I'm always forgetting how to do this and need practice. ;-)

Since usually all the complex numbers are at the top level, maybe we can almost always get by with just putting the replacement rule at the end of the Graphics section.

SeedRandom[1]
p = RandomComplex[1 + I, 6];
clrs = Table[Hue[0.8 (i - 1)/5], {i, 1, 6}];

Graphics[
{
Thick,
Table[{clrs[[i]], Circle[p[[i]], RandomReal[{0.1, 0.5}]]}, {i, 1,
6}],
Thin,
Blue, Dashed, Line[p],
AbsolutePointSize[12], Point[p, VertexColors -> clrs],
Red, BSplineCurve @ p,
Opacity[0.3, Purple], Rectangle[p[[1]], p[[-1]]],
Opacity[0.3, Green], Polygon[RandomSample[p, 6]]
}
] /. Complex[a_, b_] :> {a, b}