1. Member Join Date
Nov 2009
Posts
19
Rep Power
0

## 3d cube/shapes program

i don't know what to do im going to fail this course, they started teaching something heavy about object oriented programming failed the last assignment and now this. i need to make a program that creates 3d shapes. ill try to translate everything from my language:(i have no idea how to do this)

i need to make this

Constructor Summary
Box3D(double width, double length, double height)
Constructs a new Box, with the base corner at (0,0,0) and its dimensions are the ones
given. If any of the sides is zero or negative, it is set to 1.

Box3D(double x, double y, double z, double width, double length,
double height)
Constructs a new Box, with the base corner as the point given and its dimensions are
the ones given. If any of the sides is zero or negative, it is set to 1.

Method Summary

double getVolume()
Returns the volume of the box.

boolean isInside(double pointX, double pointY, double pointZ)
Checks if a candidate point is inside (or on the face of) the box.

void move(double dx, double dy, double dz)
Moves the box by the given delta values.

void scale(double factor)
Scales the box by the given factor. (Multiply all dimensions by
the specified factor).

java.lang.String toString()
Returns the string representation of the Box.

input exmple
Java Code:
```public static void main (String[] args) {
Box3D box1 = new Box3D (5.0, 10.0, 20.0);
Box3D box2 = new Box3D (3.0, 3.0, 3.0, 5.0, 10.0, 20.0);
Box3D box3 = new Box3D (2.0, 2.0, 4.0, 2.0, 3.0, 6.0);
System.out.println ("box1: " + box1);
System.out.println ("box1 volume: " + box1.getVolume());
box1.scale (2.5);
System.out.println ("box1 scaled by 2.5: " + box1);
System.out.println ("box1 scaled by 2.5 volume: " +
box1.getVolume());
box2.move (-8, 0, 2);
System.out.println ("box2: " + box2);
System.out.println ("box3: " + box3);
System.out.println ("Point (3, 3, 6) is inside box3? " +
box3.isInside (3, 3, 6));
System.out.println ("Point (3, 3, 2) is inside box3? " +
box3.isInside (3, 3, 2));```
output:box1: (0.0,0.0,0.0)->(5.0,10.0,20.0)
box1 volume: 1000.0
box1 scaled by 2.5: (0.0,0.0,0.0)->(12.5,25.0,50.0)
box1 scaled by 2.5 volume: 15625.0
box2: (-5.0,3.0,5.0)->(5.0,10.0,20.0)
box3: (2.0,2.0,4.0)->(2.0,3.0,6.0)
Point (3, 3, 6) is inside box3? true
Point (3, 3, 2) is inside box3? false  Reply With Quote

2. gcampton Guest

## well your going to have to catchup.
The Really Big Index
start at the subjects your not familiar with, and read read read quick. Because you are falling behind and your going to fail if you don't take drastic measures  Reply With Quote

3. Member Join Date
Nov 2009
Posts
19
Rep Power
0

## thanks i read some of the "Classes and Objects" which is the martial i need, my problem will be with making the shapes, i don't know to drew in java,and theirs the thing with the: x,y,z graph  Reply With Quote

4. ## It seems to me you're not doing anything 3d, rather, simply calculating to volume of a 3d shape. The formulas for volume calculation are really simple for boxes (height*width*depth). Scaling is also simple. So in the end, the only thing your program is really doing is taking the a measurement of 3 sides and multiplying them together, then returning the result. The point questions are also simply range checks for the 3 dimensions. Are you having trouble saving values, performing basic math and printing the results? Because I think thats all this project entails from the sound of it.  Reply With Quote

5. Member Join Date
Nov 2009
Posts
19
Rep Power
0

##  Originally Posted by quad64bit simply range checks for the 3 dimensions. Are you having trouble saving values, performing basic math and printing the results? Because I think thats all this project entails from the sound of it.
yap, i dont know how to return values,i dont know how to "range checks for the 3 dimensions"(or mabe dont understand),and mabe i suck at basic math.

if you can explain the "range checks for the 3 dimensions" it would be vary helpfull.(googled it didnt help too much)

cuz i can learn the return value thing .  Reply With Quote

6. ## Ok, lets say we have a cube. The origin is at 0,0,0 (x,y,z where x is hoz, y is vert, and z is depth on a 3d cartesian plane). Lets say it has a size of 4.

That means that the corners could be at coordinates like this:
Cube Image

We can see from the diagram that the purple point at 2,2,2 is contained inside the cube (or box). We can see the green point at 6,2,2 is NOT contained in the box.

So, if you have a box, starting at the origin of 0,0,0, with a size of 4 (which makes it a cube, sorry my cube is sloppy looking) then all you need to do to find if a given point is inside the cube is to check wether the coordinates fall within the range between the points that comprise the corners of the box.

So, you could check each coord one at a time.

so, you'd check x first. Is the x value supplied between 0 and 4? (the range of x values in our box) Yes? Ok, then check y
Is the y value between 0 and 4? yes? then check z
Is the z value between 0 and 4? Yes? Then the point is contained within the box. If the answer to any of the questions was no, then no, the point is not contained.

Hope that helps -- draw this stuff out on paper! it helps!

Also, one more note, I made my Z coords go positive as the box increases in depth and go negative as the box moves towards the screen in my diagram, your coordinate system might have the inverse, but the idea is the same.  Reply With Quote

7. Member Join Date
Nov 2009
Posts
19
Rep Power
0

## how do i use Point3D

or java.lang.String

they dont teach you anythin what kind of a univrsty are this people running?  Reply With Quote

8. ##  Originally Posted by adamrain how do i use Point3D
I haven't seen anything in this thread so far to suggest to me that you want to use Point3D. Instead, create and use the Box3D which I believe your assignment requests.

or java.lang.String
Huh? This is simply the fully qualified name of the String class.

they dont teach you anythin what kind of a univrsty are this people running?
Sorry for the lecture but in school as in life, you yourself and no one else are ultimately responsible for your own education.

As an example, I think I'm safe in saying that most of the folks here taught themselves Java, or even if they studied it at the University, still they taught the majority of what they know about the language to themselves. So it can be done, and it's not that hard but mainly requires effort and dedication.

So if you are learning java, then bravo, you should be proud of yourself. If not, then my main recommendation is to keep at it, study harder, study smarter. it's all up to you.

Much luck.
Last edited by Fubarable; 01-05-2010 at 01:59 AM.  Reply With Quote

9. ##  Originally Posted by Fubarable I think I'm safe in saying that most of the folks here taught themselves Java, or even if they studied it at the University, still they taught the majority of what they know about the language to themselves.
Agreed. I've studied java formally, and that generally involved the professor saying "Create a red-black tree in java. Good Luck.".

In other words, University is for concepts and guidance, but the language learning is all self study. Thats the whole point -- in the 'real world' you will not have a professor hand-holding you, learning will be self administered and expected of you.

I hate to say it, but if you are having trouble with String, then you must be very far behind. In which case, you really need to go back to basics and start from the beginning. Even if you pass this class, you are in no shape to take the next one at this point.

I wish you the best, don't give up.  Reply With Quote

10. Member Join Date
Nov 2009
Posts
19
Rep Power
0

## edit: Fubarable:this was only part of the assignment , and why do i see the posts in small fonts? how can i make it normal?

hi i have more luck then brains, and now i have the hole code:
the problem is the compiler says "cannot find symbol" on those lins"

*13)point = new Point3D(x,y,z);
*59)private java.lang.String toString()
*5) Point3D point;

Java Code:
```public class Box3D extends java.lang.Object  {

double width,length,height;
Point3D point;
private  Box3D(double width, double length, double height)
{
this(0.0,0.0,0.0,width,length,height);
}
private  Box3D(double x, double y, double z, double width, double length,double height)
{
point = new Point3D(x,y,z);

if (width <= 0)
{
width = 1;
}
if (length <= 0)
{
length = 1;
}
if (height <= 0)
{
height = 1;
}
this.width = width;
this.length = length;
this.height = height;
}

//Methods:
private  double getVolume()
{    //Volume = (h)(w)(l)
return (this.height * this.width * this.length);
}

private  boolean isInside(double pointX, double pointY, double pointZ)
{
//
if(!pointX<=x){return false;}
if(!pointT<=y){ return false;}
if(!pointZ<=z){ return false;}
else
{return true;}
}

private Point3D   getCenter() {  return ((this.height + this.width + this.length+this.x+this.y+this.z)/4);

}

private  void move(double dx, double dy, double dz)
{
//Moves the box by the given delta values.
this.point.x += dx;
this.point.y += dy;
this.point.z += dz;
}
private  void scale(double factor)
{
//(Multiply all dimensions by
//the specified factor).
this.width *= factor;
this.length *= factor;
this.height *= factor;
}
private  java.lang.String toString()
{
//"(x, y, z)->(width, length, height)".
return "("+this.point.x + ","+this.point.y + "," + this.point.z + ") -> " + "(" + width + "," + length + "," + height + ")";
}}```
and i have the:isInside(Point3D pnt)
Checks if a candidate point is inside (or on the face of) the box.

but i think i can use quad64bits cube picture to figure it out

and i also need to do this:
Point3D getBaseVertex()
This method returns the a copy of the base vertex (bottom, left, front) of the
box.
Last edited by adamrain; 01-05-2010 at 07:52 PM.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•