Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By JosAH
  • 1 Post By JosAH

Thread: Calculate angels of a point object

  1. #1
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Calculate angels of a point object

    Hey guys,
    I want to calculate the x & y of a point object after it hits a frame.
    Theoretical I think that the angle of the point need to be multiplied in -1 after it hits a frame.
    Practical I do not know how to implement it,

    thanks in advanced.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: Calculate angels of a point object

    want to calculate the x & y of a point object after it hits a frame.
    Are you drawing a shape that hits another shape as it is moving across your window?
    You need to consider where the two shapes are located in 2 dimensions and see when the boundary of one shape touches the boundary of the other shape. Drawing this on paper will help you to see where the boundaries are and where the boundary of one touches the boundary of the other.
    the angle of the point need to be multiplied in -1 after it hits a frame
    Not sure what you mean here. A point doesn't have an angle. Do you mean the angle between the path of the point and the boundary of the shape that the moving point is coming in contact with? Are you trying to have the point bounce off the boundary and move in a new direction?

    Do you have some code you can post to show your problem?

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: Calculate angels of a point object

    If a point travels with a speed (dx, dy) toggle the sign of dx if the point hits a vertical wall; toggle the sign of dy if it hits a horizontal wall.

    kind regards,

    Jos
    Last edited by JosAH; 11-16-2011 at 08:19 AM. Reason: fixed a stupid typo ...
    DarrylBurke likes this.
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default Re: Calculate angels of a point object

    Quote Originally Posted by Norm View Post
    Are you drawing a shape that hits another shape as it is moving across your window?
    No, I'm drawing a shape that hits the window frames.

    Quote Originally Posted by Norm View Post
    Not sure what you mean here. A point doesn't have an angle.
    I know! I just trying to find a way to calculate the new values after the object confluenction.

    Quote Originally Posted by Norm View Post
    Are you trying to have the point bounce off the boundary and move in a new direction?


    Do you have some code you can post to show your problem?

    Truthly, no.
    I just got a simple point on my screen.
    Looks like I got 2 problems now:

    1)I want the point to move randomly on the screen. Moving it with 90 degrees it's easy .. just x++ or y++ but I want the point to move as the ball move on the picture I attached.
    2)When it hits the window frame, what the values will be then?

    Quote Originally Posted by JosAH View Post
    If a point travels with a speed (dx, dy) toggle the sign of dx if the point hits a vertical wall; toggle the sign of dy if it hits a horizontal wall.
    Yea I know that but what happens if the ball is not re painting by x++ or y++, if it's x+=3, y+=10

    Thanks guys.

    edit: JoshAH, I think your answer is working for all the cases.
    I will test it now.
    Attached Thumbnails Attached Thumbnails Calculate angels of a point object-.png  

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,572
    Rep Power
    25

    Default Re: Calculate angels of a point object

    I want the point to move as the ball move on the picture I attached.
    If you change the x and/or y values over time, the location will change.

    When it hits the window frame, what the values will be then?
    Print out the values of x and y as the ball moves to see their values.
    Do you know the size of the window frame?

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: Calculate angels of a point object

    Quote Originally Posted by tnrh1 View Post
    edit: JoshAH, I think your answer is working for all the cases.
    I know, that's why I posted it ;-)

    kind regarrds,

    Jos
    tnrh1 likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Need help to calculate avg
    By vavavoom1 in forum New To Java
    Replies: 2
    Last Post: 04-02-2011, 07:42 PM
  2. Calculate Interest
    By hacikho in forum New To Java
    Replies: 4
    Last Post: 10-09-2010, 04:15 AM
  3. calculate fft
    By ram.west in forum Advanced Java
    Replies: 2
    Last Post: 08-27-2008, 03:05 AM
  4. Calculate what e1 and e2 should be
    By Legoland in forum New To Java
    Replies: 11
    Last Post: 07-02-2007, 06:01 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
  •