Results 1 to 10 of 10
  1. #1
    adamrain is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default 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

  2. #2
    gcampton Guest

    Default

    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

  3. #3
    adamrain is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    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

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    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.

  5. #5
    adamrain is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    Quote Originally Posted by quad64bit View Post
    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 .

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    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.

  7. #7
    adamrain is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    how do i use Point3D

    or java.lang.String

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

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by adamrain View Post
    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 02:59 AM.

  9. #9
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Quote Originally Posted by Fubarable View Post
    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.

  10. #10
    adamrain is offline Member
    Join Date
    Nov 2009
    Posts
    19
    Rep Power
    0

    Default

    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;
        //Constructor overloading:
        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 08:52 PM.

Similar Threads

  1. erase shapes ???
    By h9h in forum Java 2D
    Replies: 1
    Last Post: 10-12-2009, 09:11 PM
  2. Cube
    By Evil Smurf in forum Advanced Java
    Replies: 0
    Last Post: 08-30-2009, 07:22 PM
  3. Computing a cube (power of 3).
    By Jary316 in forum New To Java
    Replies: 4
    Last Post: 01-16-2009, 10:13 PM
  4. Colors and shapes.
    By Torgero in forum New To Java
    Replies: 14
    Last Post: 10-13-2008, 06:25 PM
  5. Rubiks Cube Solver
    By sufs2000 in forum Advanced Java
    Replies: 0
    Last Post: 06-03-2008, 04:20 PM

Posting Permissions

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