Index

Base.convert — Method
convert(Point3D, pt::Point, z)

Convert pt to a Point3D(pt.x, pt.y, z).

source
Base.convert — Method
convert(Point3D, pt::Point)

Convert pt to a Point3D(pt.x, pt.y, 0).

source
Luxor.between — Function
between(p1::Point3D, p2::Point3D, x=0.5)
between((p1::Point3D, p2::Point3D), x=0.5)

Find a point on a line between two 3D points. If x is 0.5, the returned point should be halfway between them.

source
Luxor.distance — Method
distance(p1::Point3D, p2::Point3D)

Return the distance between two points.

source
Luxor.drawpath — Method
drawpath(path::Path, k::Real, anchor::Point3D;
    about=Point3D(0., 0., 0.),
    rotation::Rotation=RotXYZ(0, 0, 0),
    steps=20, # used when approximating Bezier curve segments
    action=:none,
    startnewpath=true,
    pathlength = 0.0)

Draw a Luxor Path object on a 2D plane, starting at anchor with rotation about about.

source
Luxor.midpoint — Method
midpoint(pt1::Point3D, pt2::Point3D)

Find the midpoint between two points. See also between().

source
Thebes.carpet — Function
carpet(n; kind=:circular)

Draw a circular carpet centered at the origin, using current Luxor parameters.

If kind is not :circular, the carpet will be a square.

Points that can't be rendered are not included in the final shape.

source
Thebes.drawcube — Function
drawcube(n=10, action=:stroke)

Draw a cube. drawcube(1) draws a wireframe unit cube.

source
Thebes.face — Method
face(o::Object, n)

Return a vector of the 3D points that describe the nth face of the object.

source
Thebes.import_off_file — Method
import_off_file(fname)

Import a file in OFF (Object File Format).

Returns a Tuple - vertices, and faces. Vertices is a vector of [x, y, z], and faces a vector of vectors of vertex numbers.

off_file = raw"    OFF    8 6 0    -0.500000 -0.500000 0.500000    0.500000 -0.500000 0.500000    -0.500000 0.500000 0.500000    0.500000 0.500000 0.500000    -0.500000 0.500000 -0.500000    0.500000 0.500000 -0.500000    -0.500000 -0.500000 -0.500000    0.500000 -0.500000 -0.500000    4 0 1 3 2    4 2 3 5 4    4 4 5 7 6    4 6 7 1 0    4 1 7 5 3    4 6 0 2 4"f = open("/tmp/cube.off", "w") do f    write(f, off_file)    end@draw begin    o = make(import_off_file("/tmp/cube.off"))    scaleby!(o, 100)    pin(o)end
source
Thebes.make — Function
make(primitive, name="unnamed")

primitive contains two arrays, an array of 3D points, and an array of faces, where each face is a list of vertex numbers.

Returns a Object.

The following objects are defined (stored in the file ("/data/objects.jl"):

boxcube, boxtorus, concave, cone, crossshape, cube, cuboctahedron, dodecahedron, geodesic, helix2,icosahedron, icosidodecahedron, octahedron, octtorus, rhombicosidodecahedron,rhombicuboctahedron, rhombitruncated_cubeoctahedron, rhombitruncated_icosidodecahedron,snub_cube, snub_dodecahedron, sphere2, tet3d, tetrahedron, triangle, truncated_cube, truncated_dodecahedron, truncated_icosahedron, truncated_octahedron, truncated_tetrahedron

Example

make(Cube, "cube")

returns an Object object containing an array of vertices, an array of faces, and an array of labels.

@draw begin    helloworld()    tol = 0.01    a = []    sethue("black")    for t in -2pi:tol:2pi        push!(a, Point3D((50 + cos(5t)) * cos(3t), (50 + cos(5t)) * sin(2t), sin(5t)))    end    Knot = make((a, []), "knot")    pin(Knot, gfunction=(args...) -> begin        for verts in args[1].vertices            pin(verts)        end    end)end

The default gfunction expects faces - if there aren't any, use a gfunction that draws vertices.

source
Thebes.moveby! — Method
moveby!(o::Object, x, y, z)
moveby!(o::Object, pt::Point3D)

Set the position of object to Point3D(x, y, z).

source
Thebes.moveby! — Method
moveby!(ptlist::Point3D, x, y, z)
moveby!(ptlist::Point3D, pt::Point3D)

Move all points in the list by a vector.

source
Thebes.moveby — Method
moveby(o::Object, x, y, z)

Set the position of a copy of the object to Point3D(x, y, z).

source
Thebes.moveby — Method
moveby(pt::Point3D, d::Point3D)

Return a new point that's the result of moving a point pt by a vector d.

source
Thebes.newprojection — Function

newprojection(ipos::Point3D, center::Point3D, up::Point3D, perspective=0.0)

Define a new Projection:

  • ipos is the eye position
  • center is the 3D point to appear in the center of the 2D image
  • up is a point that is to appear vertically above the center

If perspective is 0.0 (the default) the projection is parallel. Otherwise it's a vague magnification factor for perspective projections.

If the up point lies on the line through the eye and the center, there's no way to tell which way is up, so the world z axis is used instead (or the y axis, if you're looking along the z axis). If the eye and the center are the same point there's no line of sight, and a degenerate projection is returned.

source
Thebes.objecttopoly — Method
objecttopoly(o::Object)

Return a tuple:

  • an array of 2D points representing the vertices of o

  • an array of 2D polygons representing the faces of o

Example

This example draws the faces of a cube in colors, and marks the vertices in black.

using Luxor, Thebes@draw begin    helloworld()    o = make(Cube)    scaleby!(o, 100, 100, 100)    vs, fs = objecttopoly(o)    setopacity(0.4)    sethue("black")    for face in fs        randomhue()        poly(face, :fill)    end    sethue("black")    circle.(vs, 3, :fill)end
source
Thebes.pin — Method
pin(o::Object;
    gfunction=(o) -> hiddensurface(o))

Draw a rendering of an object.

The default rendering function is hiddensurface().

You can also use the built-in wireframe() rendering function.

Examples

@draw begin    o = make(Cube)    axes3D(200)    scaleby!(o, 200, 200, 200)    eyepoint(250, 270, 300)    pin(o) # use an attempted hiddensurface rendering    o = make(Tetrahedron)    axes3D(200)    scaleby!(o, 200, 200, 200)    eyepoint(250, 270, 300)    pin(o, gfunction=wireframe) # use a wireframe renderingend

More help

You could write your own rendering function to draw objects.

function a_rendering_function(o::Object)   if !isempty(o.faces)       sortfaces!(o)       @layer begin           for (n, face) in enumerate(o.faces)               @layer begin                   vertices = o.vertices[face]                   sn = surfacenormal(vertices)                   ang = anglebetweenvectors(sn, eyepoint())                   setgrey(rescale(ang, 0, π, 1, 0))                   pin(vertices, gfunction = (p3, p2) ->                    begin                       poly(p2, :fill)                       sethue("white")                       poly(p2, :stroke, close=true)                    end)               end           end       end   endend
source
Thebes.pin — Method
pin(p3_1::Point3D, p3_2::Point3D;
    gfunction = ((p3_1, p3_2), (p2_1, p2_2)) ->
        line(p2_1, p2_2, :stroke))

Draw two 3D points.

The default action is to draw a line between two points.

The gfunction can access the 3D points as the first argument, the two 2D points in the second argument.

pin(p, Point3D(50cos(θ), 50sin(θ), p.z),    gfunction = (p3s, p2s) -> begin        line(p2s..., :stroke)    end)

Returns the two 2D points.

source
Thebes.pin — Method
pin(pt::Point3D;
    gfunction = (p3, p2) -> circle(p2, 1, :stroke))

Draw a single 3D point on the current Luxor drawing.

The default graphic is a circle. You can define others using a custom gfunction, which takes two arguments: the 3D point and its 2D counterpoint.

For example, this draws a circle whose radius is larger if the point is nearer to the eye.

pin(p, gfunction = (p3, p2) -> begin        d = distance(p3, eyepoint())        circle(p2, rescale(d, 0, 300, 20, 5), :fill)    end    )

Returns the 2D point.

source
Thebes.pin — Method
pin(p3list::Array{Point3D, 1};
    gfunction = (p3list, p2list) ->
        poly(p2list, :stroke, close=true))

Draw an array of 3D points.

The default action is to draw a polygon through all the points.

The gfunction can access the 3D points as the first argument, the two 2D points in the second argument.

helix = [Point3D(100cos(θ), 100sin(θ), 20θ) for θ in 0:π/12:4π]a_box = pin(helix, gfunction =    (p3list, p2list) -> prettypoly(p2list, :stroke)    )

Returns the list of 2D points.

source
Thebes.pointsperpendicular — Function
pointsperpendicular(p1::Point3D, p2::Point3D, radius, angles = [0, π])

Find points perpendicular to a line joining p1 and p2. Points are radius units away from the line.

source
Thebes.project — Method

project(P::Point3D)

Project a 3D point onto a 2D surface, as defined by the current projection.

TODO Currently this returns 'nothing' if the point is behind the eyepoint. This makes handling the conversion a bit harder, though, since the function now returns either a 2D Luxor point or nothing.

using Thebes, Luxor@svg begin    eyepoint(Point3D(250, 250, 100))    centerpoint(Point3D(0, 0, 0))    uppoint(Point3D(0, 0, 10))    sethue("grey50")    carpet(300)    axes3D(100)    sethue("red")    for i in 1:30        randpoint3D = Point3D(rand(0.0:150, 3)...)        sethue("red")        pt1 = pin(randpoint3D)        if pt1 != nothing            circle(pt1, 5, :fill)        end    endend
source
Thebes.projection — Method
projection()

Define a new Projection:

  • the eye position is Point3D(100, 100, 100)`
  • the center point is Point3D(0, 0, 0)
  • the "up" point is Point3D(0, 0, 1)
  • perspective is 0 (parallel projection)
source
Thebes.rotateX — Method
rotateX(pt3D::Point3D, rad)

Return a new point resulting from rotating the point around the x axis by an angle in radians.

Rotations are anticlockwise when looking along axis from 0 to +axis.

source
Thebes.rotateY — Method
rotateY(pt3D::Point3D, rad)

Return a new point resulting from rotating the point around the y axis by an angle in radians.

Rotations are anticlockwise when looking along axis from 0 to +axis.

source
Thebes.rotateZ — Method
rotateZ(pt3D::Point3D, rad)

Return a new point resulting from rotating the point around the z axis by an angle in radians.

source
Thebes.rotateby — Function
rotateby(o::Object, pt::Point3D, r::Rotation=RotXYZ(0, 0, 0))

Rotate a copy of the object around a point by rotation r.

source
Thebes.rotateby! — Function
rotateby!(ptlist::Array{Point3D, 1}, r::Rotation=RotXYZ{Float64})

Rotate each point in the list by rotation (or angleX, angleY, angleZ) around another point (or origin).

source
Thebes.rotateby! — Function
rotateby!(o::Object, pt::Point3D, r::Rotation=RotXYZ(0, 0, 0))

Rotate an object around a point by rotation r, or angleX, angleY, angleZ.

source
Thebes.rotateby! — Method
rotateby!(o::Object, angleX, angleY, angleZ)

Rotate an object through rotation r around the x, y, and/or z axis by angleX, angleY, angleZ.

source
Thebes.rotateby! — Method
rotateby!(o::Object, pt::Point3D, angleX, angleY, angleZ)

Rotate an object around a point by angleX, angleY, angleZ.

source
Thebes.rotateby! — Method
rotateby!(ptlist::Array{Point3D, 1}, angleX, angleY, angleZ)

Modify a list of points by rotating each one around the x, y, and z axes by angleX, angleY, angleZ.

source
Thebes.rotateby! — Method
rotateby!(ptlist::Array{Point3D, 1}, existingpt::Point3D, angleX, angleY, angleZ)

Rotate each point in the list by angleX, angleY, angleZ around another point (or origin).

source
Thebes.rotateby! — Method
rotateby!(ptlist::Array{Point3D, 1}, existingpt::Point3D, r::Rotation)

Rotate each point in the list by rotation around another point (or origin).

source
Thebes.rotateby — Method
rotateby(o::Object, angleX, angleY, angleZ)

Rotate a copy of the object by angleX, angleY, angleZ.

source
Thebes.rotateby — Method
rotateby(o::Object, pt::Point3D, angleX, angleY, angleZ)

Rotate a copy of the object around a point by rotation r, or angleX, angleY, angleZ.

source
Thebes.rotateby — Method
rotateby(o::Object, r:Rotation)

Rotate a copy of the object by the Rotation r.

source
Thebes.rotateby — Method
rotateby(pt::Point3D, angleX, angleY, angleZ)
rotateby(ptlist::Array{Point3D, 1}, angleX, angleY, angleZ)
rotateby(point::Point3D, r::Rotation)
rotateby(ptlist::Array{Point3D, 1}, r::Rotation)

Return a new point/list of points resulting from rotating around the x, y, and z axes by angleX, angleY, angleZ.

The Z rotation is first, then the Y, then the X.

A 3×3 rotation matrix parameterized by the "Tait-Bryant" XYZ Euler angle convention, consisting of first a rotation about the Z axis by theta3, followed by a rotation about the Y axis by theta2, and finally a rotation about the X axis by theta1.

source
Thebes.rotateby — Method
rotateby(point::Point3D, about::Point3D, angleX, angleY, angleZ)
rotateby(point::Point3D, about::Point3D, r::Rotation)
rotateby(ptlist::Array{Point3D, 1}, about::Point3D, r::Rotation)

Rotate point.

source
Thebes.scaleby! — Method
scaleby!(ptlist::Array{Point3D, 1}, x, y, z)

Scales a list of points by multiplying by x in X, y in Y, z in Z.

source
Thebes.sortfaces! — Method
sortfaces!(o::Object;
    eyepoint::Point3D=eyepoint())

Find the averages of the z values of the faces in Object, and sort the faces of o so that the faces are in order of nearest (highest) z relative to eyepoint...

source
Thebes.sphericaltocartesian — Method
sphericaltocartesian(ρ, θ, ϕ)

Return Point3D(x, y, z) corresponding to (ρ, θ, ϕ):

  • ρ is the distance from the origin (ie radius)

  • θ is the azimuthal angle (the longitude) 0 is +x, π is -x, 2π is +x

  • ϕ is the polar angle (the colatitude) 0 is North Pole, π is South Pole

There are two major conventions for spherical coordinate notation.

In physics books:

(ρ, θ, φ) gives the radial distance, polar angle (colatitude), and azimuthal angle (longitude)

In mathematics books:

(ρ, θ , φ ) gives the radial distance, azimuthal angle (longitude), and polar angle (colatitude)

So we're using the mathematics one here.

source
Thebes.text3D — Method
 text3D(str, anchor::Point3D;
    halign=:left,
    valign=:baseline,
    about=Point3D(0., 0., 0.),
    rotation::Rotation=RotXYZ(0, 0, 0))

Draw text at point pt, lying in the plane of the x axis. Angles in rotation rotate the text about the about point, defaulting to Point3D(0, 0, 0).

Uses Luxor's fontface() and fontsize() settings.

Specify rotations using functions from Rotations.jl, such as:

  • RotX(a)
  • RotZ(a)
  • RotXZ(a1, a2)
  • RotXYZ(a1, a2, a3)
source
Thebes.uppoint — Method
uppoint(x, y, z)

Specify the "up" direction for the world: a line from the centerpoint to the uppoint defines the up direction.

source
Thebes.uppoint — Method
uppoint(pt::Point3D)

Specify the "up" direction for the world: a line from the centerpoint to the uppoint defines the up direction.

source
Thebes.uppoint — Method
uppoint()
uppoint(pt::Point3D)

The "up" direction for the world: a line from the centerpoint to the uppoint defines the up direction.

source
Thebes.wireframe — Method
wireframe(o::Object)

Given an object o, sort the faces in o.faces, then draw grey stroked polygons for each face.

source