001/* 002 * Renderer Models. The MIT License. 003 * Copyright (c) 2022 rlkraft@pnw.edu 004 * See LICENSE for details. 005*/ 006 007package renderer.models_L; 008 009import renderer.scene.*; 010import renderer.scene.primitives.*; 011 012/** 013 Create a wireframe model of a cube with its center 014 at the origin, having edge length 2, and with its 015 vertices at {@code (±1, ±1, ±1)}. 016<p> 017 Here is a picture showing how the cube's eight 018 corners are labeled. 019<pre>{@code 020 v4=(-1,1,-1) 021 +---------------------+ v5=(1,1,-1) 022 /| /| 023 / | / | 024 / | / | 025 / | / | 026 / | / | 027 v7 +---------------------+ v6 | 028 | | | | 029 | | | | 030 | | v0=(-1,-1,-1) | | 031 | +---------------|-----+ v1=(1,-1,-1) 032 | / | / 033 | / | / 034 | / | / 035 | / | / 036 |/ |/ 037 +---------------------+ 038 v3=(-1,-1,1) v2=(1,-1,1) 039}</pre> 040 See <a href="https://en.wikipedia.org/wiki/Cube" target="_top"> 041 https://en.wikipedia.org/wiki/Cube</a> 042 043 @see Tetrahedron 044 @see Octahedron 045 @see Icosahedron 046 @see Dodecahedron 047*/ 048public class Cube extends Model 049{ 050 /** 051 Create a cube with its center at the origin, having edge 052 length 2, and with its vertices at {@code (±1, ±1, ±1)}. 053 */ 054 public Cube( ) 055 { 056 this("Cube"); 057 } 058 059 060 /** 061 Create a cube with its center at the origin, having edge 062 length 2, and with its vertices at {@code (±1, ±1, ±1)}. 063 064 @param name a {link String} that is a name for this {@code Cube} 065 */ 066 public Cube(final String name) 067 { 068 super(name); 069 070 // Create 8 vertices. 071 addVertex(new Vertex(-1, -1, -1), // 4 vertices around the bottom face 072 new Vertex( 1, -1, -1), 073 new Vertex( 1, -1, 1), 074 new Vertex(-1, -1, 1), 075 new Vertex(-1, 1, -1), // 4 vertices around the top face 076 new Vertex( 1, 1, -1), 077 new Vertex( 1, 1, 1), 078 new Vertex(-1, 1, 1)); 079 080 // Create 12 line segments. 081 addPrimitive(new LineSegment(0, 1), // bottom face 082 new LineSegment(1, 2), 083 new LineSegment(2, 3), 084 new LineSegment(3, 0), 085 new LineSegment(4, 5), // top face 086 new LineSegment(5, 6), 087 new LineSegment(6, 7), 088 new LineSegment(7, 4), 089 new LineSegment(0, 4), // back face 090 new LineSegment(1, 5), 091 new LineSegment(2, 6), // front face 092 new LineSegment(3, 7)); 093 } 094}//Cube