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 square in the xy-plane centered at the origin. 014<p> 015 Here is a picture showing how the square's four vertices are labeled. 016<pre>{@code 017 y 018 | 019 | 020 v1 | v2 021 +----------------------+ 022 | | | 023 | | | 024 | | | 025 | | | 026 ------|----------+-----------|-------> x 027 | | | 028 | | | 029 | | | 030 +----------------------+ 031 v0 | v3 032 | 033 | 034}</pre> 035*/ 036public class Square extends Model 037{ 038 /** 039 Create a square in the xy-plane with corners {@code (±1, ±1, 0)}. 040 */ 041 public Square( ) 042 { 043 this(1); 044 } 045 046 047 /** 048 Create a square in the xy-plane with corners {@code (±r, ±r, 0)}. 049 050 @param r determines the corners of the square 051 @throws IllegalArgumentException if {@code r} is less than or equal to 0 052 */ 053 public Square(final double r) 054 { 055 super(String.format("Square(%.2f)", r)); 056 057 if (r <= 0) 058 throw new IllegalArgumentException("r must be greater than 0"); 059 060 // Create the square's geometry. 061 addVertex(new Vertex(-r, -r, 0), 062 new Vertex(-r, r, 0), 063 new Vertex( r, r, 0), 064 new Vertex( r, -r, 0)); 065 066 addPrimitive(new LineSegment(0, 1), 067 new LineSegment(1, 2), 068 new LineSegment(2, 3), 069 new LineSegment(3, 0)); 070 } 071}//Square