Ask Your Question
1

How can we label 3d cube?

asked 2022-06-27 16:36:05 +0100

aakkbb gravatar image

updated 2022-06-27 16:36:23 +0100

If we use cube() function we get a nice cube without vertices labelled. I could not find any inbuilt method to label vertices. Is there any way to do this?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2022-06-27 23:59:29 +0100

Juanjo gravatar image

Yes, you can use text3d. The following code may give you some ideas:

v_opt = dict(fontsize="200%", fontfamily="palatino", fontstyle="italic", color="blue")
f_opt = dict(fontsize="200%", fontfamily="palatino", fontstyle="italic", color="black")

fig = cube(center=(0.5,0.5,0.5), size=1, color="lightgreen", frame_thickness=2, 
           frame_color="red", opacity=0.8)
fig += (text3d("A", (1.02,0,0), **v_opt) + text3d("B", (1.02,1.02,0), **v_opt)
        + text3d("C", (1.02,1.02,1.02), **v_opt) + text3d("D", (1.02,0,1.02), **v_opt)
        + text3d("E", (-0.02,0,0), **v_opt) + text3d("F", (-0.02,1.02,0), **v_opt)
        + text3d("G", (-0.02,1.02,1.02), **v_opt) + text3d("H", (-0.02,0,1.02), **v_opt))
fig += (text3d("front", (1.05,0.5,0.5),**f_opt) + text3d("back", (-0.05,0.5,0.5),**f_opt)
        + text3d("left", (0.5,-0.05,0.5),**f_opt) + text3d("right", (0.5,1.05,0.5),**f_opt)
        + text3d("up", (0.5,0.5,1.05),**f_opt) + text3d("down", (0.5,0.5,-0.05),**f_opt))
show(fig, frame=False)

This is the result, that you can also see in SageCell: image description

edit flag offensive delete link more

Comments

Use threejs_flat_shading to get a more appropriate shading:

fig = cube(center=(0.5,0.5,0.5), size=1, color="lightgreen", frame_thickness=2,
       frame_color="red", opacity=0.8, threejs_flat_shading=True)

One would have hoped that problem to be over with Sage Trac ticket 31426 merged in Sage 9.6.beta4. Seems we need a follow-up ticket.

slelievre gravatar imageslelievre ( 2022-06-28 06:26:33 +0100 )edit
0

answered 2022-06-28 06:58:19 +0100

slelievre gravatar image

Two graphs are related:

  • graphs.CubeGraph(3)
  • graphs.GridGraph([2, 2, 2])

Their 2d plots and latexed forms have labels, but the 3d plots do not.

Cube graph

Define the cube graph

sage: C = graphs.CubeGraph(3)
sage: C
3-Cube: Graph on 8 vertices

Check its 2d plot, latex view, and 3d plot:

sage: C.plot()

Cube graph plot

sage: view(C)

Cube graph view

sage: C.plot3d()

Cube graph 3d plot

There is an option to get a different embedding:

sage: D = graphs.CubeGraph(3, embedding=2)
sage: D
3-Cube: Graph on 8 vertices

Check its 2d plot, latex view, and 3d plot:

sage: D.plot()

Cube graph plot with alternate embedding

sage: view(D)

Cube graph view with alternate embedding

sage: D.plot3d()

Cube graph 3d plot with alternate embedding

Grid graph

The grid graph displays better:

sage: G = graphs.GridGraph([2, 2, 2])
sage: G
Grid Graph for [2, 2, 2]: Graph on 8 vertices

sage: G.plot()
Launched png viewer for Graphics object consisting of 21 graphics primitives

Grid graph plot

sage: view(G)

Grid graph view

sage: G.plot3d()
Launched html viewer for Graphics3d Object

Grid graph 3d plot

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-06-27 16:36:05 +0100

Seen: 246 times

Last updated: Jun 28 '22