Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

More Java Trouble, like, I should really start goin to lectures....

  • 29-10-2001 2:03pm
    #1
    Posts: 0


    Hey guyz,

    Once more I'm a tad stumped on a bit of the aul java stuff.

    Heres my prob:

    My mission is to create a class that defines an ellipse e in terms of x, y, w, h. Then write an applet that draws 2 ellipses from e that touch at only one place.

    I can write the ellipse e ok.
    I can then draw two circles from e ok.


    ....BUT to make them touch only once, Im gonna need to know the centre point of the circle and draw the second one in terms of that right?...i think thats right...

    As the Ellipse2D() thing is based on a rectangle I think I can use
    this
    getCenterX
    public double getCenterX()
    Returns the X coordinate of the center of the framing rectangle of the Shape in double precision.
    Returns:
    the x coordinate of the framing rectangle of the Shape object's center.
    

    and its y equivalent but where to put that and how to create the second Ellipse in terms of it and e is well beyond me.

    Am I on the right track here? Can ne1 push me in the right direction?

    Deadline is Wednesday 5pm btw


Comments

  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Hey psIRE,
    Are you sure you're allowed to use the Ellipse2D class? Normally when these sort of assignments are given they want you to write your own implementation.

    Either way though, if you're drawing an ellipse with position (x,y) and dimensions w,h then drawing another ellipse at (x+w,y) with the same dimensions should give you two ellipses side by side which touch in one place. I'm not sure if this will work cause I've never really worked with Ellipses, but it's worth a try.

    Let us know.


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Hmmm,

    It turns out that your problem is not Java related at all (and there I was getting all excited ;) )

    It's got to do with 2D mathematics, from what I can see anyway. I'm sure if you had to do this in C++, you would have the same problems, and this thread would be called More C++ Trouble,... (funnily enough).

    I would start going to lectures a tad more m8 ;)

    ;-phobos-)


  • Registered Users, Registered Users 2 Posts: 2,281 ✭✭✭DeadBankClerk


    Originally posted by psIRE
    My mission is to create a class that defines an ellipse e in terms of x, y, w, h. Then write an applet that draws 2 ellipses from e that touch at only one place.


    gary, your mission is to define the class, as said above, are u allowed your pre-written classes?

    also i interperated the project like this
    e is the elipse, which you are to draw.
    then you are to draw two other elipses that touch e at only one place ?


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    well if you do have to draw it yourself, the equations you'll need are

    x = (cos(theta)*ellipseWidth) + ellipseCenterX
    y = (sin(theta)*ellipseHeight) + ellipseCenterY

    for each point along the ellipse. theta is an angle you increment from 0 to 360 degrees (when implementing, don't forget Math.cos() and Math.sin() take radians, not degrees) - the smaller the increment, the closer an approximation you'll get. The easiest way to do it is to draw lines from one point to the next, that way you won't have any gaps in the ellipse no matter how poorly approximated it is.

    Then if you have to draw 2 more ellipses touching it at one point, draw them at (x+(width*2),y) and (x-(width*2),y).

    Simple, eh? :p


  • Posts: 0 [Deleted User]


    Ahhhh, soz, I have misunderstood the Question it seems.

    My greatest apologies guys, I appreciate yr help.

    Where I went wrong was I thought Ellipse2D() 's x,y,w,h were the coordinates of the inner rectangle so if I merely added w to x for the second ellipse i would have gotten them to touch twice. As it turns out the Question isn't newhere near as complicated as I thought as IT is the exterior rectangle co-ordinates used.

    Here it is neway:
    import java.applet.*;
    import java.awt.*;
    import java.awt.geom.*;
    
    /* Applet that displays 2 Ellipses that touch once. */
    
    public class TwoEllipse extends Applet
    {  
    public void paint(Graphics g)
    {  
    Graphics2D g2 = (Graphics2D) g;
    
    Ellipse2D.Double e = new Ellipse2D.Double(70,160,40,70);
    g2.draw(e);
    
    Ellipse2D.Double e2 = new Ellipse2D.Double(110,160,40,70);
    g2.draw(e2);
    }
    }
    

    Big pile of poo easy Question really. Shame, I thought id found one i could really get my teeth into :(

    Thanx again guys.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Originally posted by psIRE
    My mission is to create a class that defines an ellipse e in terms of x, y, w, h. Then write an applet that draws 2 ellipses from e that touch at only one place.
    Looks like you've done the second bit, but not the first. I don't think you're gonna get many marks for handing in that code, but hey, if you don't want to listen to us then it's your problem I guess. :rolleyes:

    If that's all you're meant to do then my apologies, but it just seems like a bit of a pointless programming excercise doesn't it?


  • Posts: 0 [Deleted User]


    to put it bluntly it was pointless yes :/

    That isn't to say I don't wanna listen to u guyz, its just i misunderstood the Q wrong so explained it to you guys wrong. I fell in to the it can't be that simple trap..........


Advertisement