Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using java to code the Cube class without using gpt This class represents a single face of a cube in 3 dimensional Cartesian space. (

using java to code the Cube class without using gpt
This class represents a single face of a cube in 3 dimensional Cartesian space. (A square) A Square is comprised of 2 Triangles that share 2 Vertices (Points) and have identical "Surface Normals" (their UnitVectors point the same direction).
Fields
Field Name
Type
Access Modifier
Description
mesh
Triangle[]
private
An array of Triangles that combine to make this Face (a bounded square).
surfaceNormal
UnitVector
private
The the surface normal of this Face.
Constructor
Access Modifier
Constructor Name
Input Parameters
Description
public
Face
Triangle one,
Triangle two,
If triangle one and two share two common vertices and their surface normals are equal. Construct a newly allocated Face object and instantiate the fields to their respective parameters. Triangle one should be index 0 of mesh.
If the two triangles do not share at least two vertices or the surface normals are not equal then each triangle should be set to Triangle() and the unit vector set to invalid (all fields 0.000).
public
Face
none
Construct a newly allocated Face object and instantiate the fields as follows: each triangle should be set to Triangle() and the unit vector set to invalid (all fields 0.000).(The face is invalid)
Methods
Method Name
Return Type
Access Modifier
Input Parameters
Description
getMesh
Triangle[]
public
None
Returns the Triangle array that makes up the mesh of this Face.
getSurfaceNormal
UnitVector
public
None
Returns the UnitVector representing the surfaceNormal of this Face.
flipSurfaceNormal
void
public
None
Flips the direction of the Surface Normal of this Face, and all of its Triangles.
compareTo
boolean
public
Face face
Compares this Face to face. Return true if the Triangles share the same vertices and normal vectors. For this assignment double variables are considered equal if they are within +/-0.0001 precision of each other, see note at the end. Otherwise return false.
isSimilar
boolean
public
Face face
Compares this Face to face. Returns true if the triangles share the same vertices (in any order) OR have the same normal vectors. Otherwise return false.
toString
String
public
None
Returns the String representation of this Triangle.
For Example, given the following fields:
Triangle[0]:
vertexA=(x0.000, y0.000, z1.000)
vertexB=(x1.000, y-1.000, z1.000)
vertexC=(x1.000, y0.000, z1.000)
surfaceNormal =<0.000i,0.000j,1.000k>
Triangle[1]:
vertexA=(x0.000, y0.000, z1.000)
vertexB=(x0.000, y-1.000, z1.000)
vertexC=(x1.000, y-1.000, z1.000)
surfaceNormal =<0.000i,0.000j,1.000k>
surfaceNormal =<0.000i,0.000j,1.000k>
The result of calling toString() would be:
{F[A(x0.000, y0.000, z1.000); B(x1.000, y-1.000, z1.000); C(x1.000, y0.000, z1.000)][A(x0.000, y0.000, z1.000); B(x0.000, y-1.000, z1.000); C(x1.000, y-1.000, z1.000)] N<0.000i,0.000j,1.000k>}
Note: The surface normal for the triangles are not printed, only the one for the face.
Note: This is one continuous string with no new line characters.
If any Triangle is invalid the result of toString() should be:
{InvalidFace}
Cube.java
This class represents a Square in 3 dimensional Cartesian space. A Cube is comprised of 6 Faces (squares) where each face shares an edge (has 2 common vertices) with 4 other faces and faces that do not share an edge have opposite surface normal vectors (One face has the inverse UnitVector of the other).
Fields
Field Name
Type
Access Modifier
Description
mesh
Face[]
private
An array of Faces that make up the mesh of the Cube.
Constructor
Access Modifier
Constructor Name
Input Parameters
Description
public
Cube
Face one,
Face two,
Face three,
Face four,
Face five,
Face six
Construct a newly allocated Cube object and instantiate the fields to their respective parameters.
Confirm that each face shares exactly one edge with each of 4 other faces. Confirm that no face is the same as another face. Confirm that each surfaceNormal of opposed Faces (faces that do not share an edge) is pointing in an opposite direction.
If any of the above is false, set each face in mesh to be an invalid face. (all fields 0.000).
Note: mesh[0] should be instantiated to Face one and so on to mesh[5] being Face six.
public
Cube
none
Construct a newly allocated Cube object and instantiate each Face in the mesh array to be invalid, all values are 0.000.
Methods
Method Name
Return Type
Access Modifier
Input Parameters
Description
getMesh
Face[]
public
None
Returns the Face array representing the entire surface mesh of the Cube.
toString
String
public
None
Returns the String representation of this Cube.
The output should be in the format of:
"|C"+ the toString() of each face. +"|"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Database Technology Edbt 88 International Conference On Extending Database Technology Venice Italy March 14 18 1988 Proceedings Lncs 303

Authors: Joachim W. Schmidt ,Stefano Ceri ,Michele Missikoff

1988th Edition

3540190740, 978-3540190745

More Books

Students also viewed these Databases questions