3.4.6 The arc Command

Partial arcs of circles may be drawn using the arc command. This has similar syntax to the circle command, but takes two additional angles, measured clockwise from the upward vertical direction, which specify the extent of the arc to be drawn. The arc is drawn clockwise from start to end, and hence the following two instructions draw two complementary arcs which together form a complete circle:

set multiplot
arc at 0,0 radius 5 from -90 to   0 with lw 3 col red
arc at 0,0 radius 5 from   0 to -90 with lw 3 col green

If a fillcolour is specified, then a pie-wedge is drawn:

arc at 0,0 radius 5 from 0 to 30 with lw 3 fillcolour red

A labelled diagram of a triangle.

In this example, we make a subroutine to draw labelled diagrams of the interior angles of triangles, taking as its inputs the lengths of the three sides of the triangle to be drawn and the position of its lower-left corner. The subroutine calculates the positions of the three vertices of the triangle and then labels them. We use PyXPlot’s automatic handling of physical units to generate the LaTeX strings required to label the side lengths in centimetres and the angles in degrees. We use PyXPlot’s arc command to draw angle symbols in the three corners of a triangle.

# Define subroutine for drawing triangles
subroutine TriangleDraw(Bx,By,AB,AC,BC)
{
# Use cosine rule to find interior angles
ABC = acos((AB**2 + BC**2 - AC**2) / (2*AB*BC))
BCA = acos((BC**2 + AC**2 - AB**2) / (2*BC*AC))
CAB = acos((AC**2 + AB**2 - BC**2) / (2*AC*AB))

# Positions of three corners of triangle
Cx = Bx + BC          ; Cy = By
Ax = Bx + AB*cos(ABC) ; Ay = By + AB*sin(ABC)

# Draw triangle
line from Ax,Ay to Bx,By
line from Ax,Ay to Cx,Cy
line from Bx,By to Cx,Cy

# Draw angle symbols
ArcRad = 4*unit(mm) # Radius of angle arcs
arc at Bx,By radius ArcRad from  90*unit(deg)-ABC to  90*unit(deg)
arc at Cx,Cy radius ArcRad from -90*unit(deg)     to -90*unit(deg)+BCA
arc at Ax,Ay radius ArcRad from  90*unit(deg)+BCA to 270*unit(deg)-ABC

# Label lengths of sides
set unit of length cm # Display lengths in cm
set numeric sigfig 3 display latex # Correct to 3 significant figure
set fontsize 1.2 # And in slightly bigger text than normal
TextGap = 1*unit(mm)
text "%s"%(BC) at (Bx+Cx)/2,(By+Cy)/2 gap TextGap hal c val t
text "%s"%(AB) at (Ax+Bx)/2,(Ay+By)/2 gap TextGap rot ABC hal c val b
text "%s"%(AC) at (Ax+Cx)/2,(Ay+Cy)/2 gap TextGap rot -BCA hal c val b

# Label angles
set unit of angle degree # Display angles in degrees
ArcRad2 = 1.4 * ArcRad # Distance of text from apex of angles
text "%s"%(CAB) at Ax+ArcRad2*sin(ABC-BCA),Ay-ArcRad2*cos(ABC-BCA) hal c val t
text "%s"%(ABC) at Bx+ArcRad2*cos(ABC/2),By+ArcRad2*sin(ABC/2) hal l val c
text "%s"%(BCA) at Cx-ArcRad2*cos(BCA/2),Cy+ArcRad2*sin(BCA/2) hal r val c

# Label points ABC
text "A" at Ax,Ay gap TextGap hal c val b
text "B" at Bx,By gap TextGap hal r val c
text "C" at Cx,Cy gap TextGap hal l val c
}

# Display diagram with three triangles
set multiplot ; set nodisplay
call TriangleDraw(2.8*unit(cm),3.4*unit(cm), 3*unit(cm),4*unit(cm),4*unit(cm))
call TriangleDraw(0.0*unit(cm),0.0*unit(cm), 3*unit(cm),4*unit(cm),5*unit(cm))
call TriangleDraw(6.5*unit(cm),0.0*unit(cm), 3*unit(cm),3*unit(cm),3*unit(cm))
set display ; refresh

The resulting diagram is shown below:

\includegraphics{examples/eps/ex_triangle}

A labelled diagram of a converging lens forming a real image.

In this example, we make a subroutine to draw labelled diagrams of converging lenses forming real images.

subroutine LensDraw(x0,y0,u,h,f)
{
# Use the thin-lens equation to find v and H
v = 1/(1/f - 1/u)
H = h * v / u

# Draw lens
lc = 5.5*unit(cm) # Radius of curvature of lens
lt = 0.5*unit(cm) # Thickness of lens
la = acos((lc-lt/2)/lc) # Angular size of lens from centre of curvature
lh = lc*sin(la) # Physical height of lens on paper
arc at x0-(lc-lt/2),y0 radius lc from  90*unit(deg)-la to  90*unit(deg)+la
arc at x0+(lc-lt/2),y0 radius lc from 270*unit(deg)-la to 270*unit(deg)+la
set texthalign right ; set textvalign top
point at x0-f,y0 label "$f$"
set texthalign left  ; set textvalign bottom
point at x0+f,y0 label "$f$"

# Draw object and image
arrow from x0-u,y0 to x0-u,y0+h with lw 2
arrow from x0+v,y0 to x0+v,y0-H with lw 2
text "$h$" at x0-u,y0+h/2 hal l val c gap unit(mm)
text "$H$" at x0+v,y0-H/2 hal l val c gap unit(mm)

# Draw construction lines
line from x0-u,y0 to x0+v,y0 with lt 2 # Optic axis
line from x0-u,y0+h to x0+v,y0-H # Undeflected ray through origin
line from x0-u,y0+h to x0,y0+h
line from x0,y0+h to x0+v,y0-H
line from x0+v,y0-H to x0,y0-H
line from x0,y0-H to x0-u,y0+h

# Label distances u and v
ylabel = y0-lh-2*unit(mm)
arrow from x0-u,ylabel to x0,ylabel with twoway lt 2
arrow from x0+v,ylabel to x0,ylabel with twoway lt 2
text "$u$" at x0-u/2,ylabel hal c val t gap unit(mm)
text "$v$" at x0+v/2,ylabel hal c val t gap unit(mm)
}

# Display diagram of lens
set unit angle nodimensionless
set multiplot ; set nodisplay
call LensDraw(0*unit(cm),0*unit(cm), 5*unit(cm),1.5*unit(cm),2*unit(cm))
set display ; refresh

The resulting diagram is shown below:

\includegraphics{examples/eps/ex_lenses}