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 cuboid aligned with 014 the x, y, and z axes and with one corner at the 015 origin. 016<p> 017 Here is a picture showing how the cuboid's eight 018 vertices are labeled. 019<pre>{@code 020 y 021 | 022 | v4 023 +---------------------+ v5 024 /| /| 025 / | / | 026 / | / | 027 / | / | 028 / | / | 029 v7 +---------------------+ v6 | 030 | | | | 031 | | | | 032 | | v0=(0,0,0) | | v1 033 | +---------------|-----+------> x 034 | / | / 035 | / | / 036 | / | / 037 | / | / 038 |/ |/ 039 +---------------------+ 040 /v3 v2 041 / 042 z 043}</pre> 044 See <a href="https://en.wikipedia.org/wiki/Cuboid" target="_top"> 045 https://en.wikipedia.org/wiki/Cuboid</a> 046 047 @see Cube 048*/ 049public class Box extends Model 050{ 051 /** 052 Create a {@code Box} with all three sides of length 1. 053 */ 054 public Box( ) 055 { 056 this(1, 1, 1); 057 } 058 059 060 /** 061 Create a {@code Box} with the given side lengths. 062 063 @param xs the size of the {@code Box} along the x-axis 064 @param ys the size of the {@code Box} along the y-axis 065 @param zs the size of the {@code Box} along the z-axis 066 */ 067 public Box(final double xs, final double ys, final double zs) 068 { 069 super(String.format("Box(%.2f,%.2f,%.2f)", xs, ys, zs)); 070 071 // Create 8 vertices. 072 addVertex(new Vertex(0, 0, 0), // 4 vertices around the bottom face 073 new Vertex(0+xs, 0, 0), 074 new Vertex(0+xs, 0, 0+zs), 075 new Vertex(0, 0, 0+zs), 076 new Vertex(0, 0+ys, 0), // 4 vertices around the top face 077 new Vertex(0+xs, 0+ys, 0), 078 new Vertex(0+xs, 0+ys, 0+zs), 079 new Vertex(0, 0+ys, 0+zs)); 080 081 // Create 12 line segments. 082 addPrimitive(new LineSegment(0, 1), // bottom face 083 new LineSegment(1, 2), 084 new LineSegment(2, 3), 085 new LineSegment(3, 0), 086 new LineSegment(4, 5), // top face 087 new LineSegment(5, 6), 088 new LineSegment(6, 7), 089 new LineSegment(7, 4), 090 new LineSegment(0, 4), // back face 091 new LineSegment(1, 5), 092 new LineSegment(2, 6), // front face 093 new LineSegment(3, 7)); 094 } 095}//Box