Closed Thread
Results 1 to 5 of 5

Thread: Solving a geometric problem.

  1. #1
    Chris Patuzzo is offline Newbie
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Solving a geometric problem.

    Hi there, I'm new to these forums.

    I was hoping to get some help with writing a method to solve a geometric problem in Java.

    The problem goes something like this:

    A tank stands in a random location of a field surrounded by a fence. It fires a projectile at a random bearing. Find where it hits the fence.

    We already know these values:

    fieldWidth
    fieldHeight
    tankX
    tankY
    bearing

    I hoped the structure could be something like this:

    Code:
    class CoOrdinate {
      private double x;
      private double y;
    
      public coOrdinate(double x, double y) {
        this.x = x;
        this.y = y;
      }
    
      public double getX() {
        return x;
      }
    
      public double getY() {
        return y;
      }
    }
    
    class Projectile {
      private double fieldWidth = 500;
      private double fieldHeight = 1000;
      private double tankLocation = new CoOrdinate(50, 810);
      private double bearing = 165; //Between 0 and 359
      
      public CoOrdinate getHitCoOrdinate() {
        //Find the co-ordinate it hits at.
        return hitCoOrdinate;
      }
    }
    I'm not so good at maths or geometry so I was hoping someone could help me write the method to solve this problem.

    Thanks a lot for your time.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Solving a geometric problem.

    Are you familiar with trigonometry? Your answer to that will determine how much detail I go into.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Chris Patuzzo is offline Newbie
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Re: Solving a geometric problem.

    Yes, I've studied maths and further maths at A level. I'm familiar with it, but I may be a little rusty.

  5. #4
    Chris Patuzzo is offline Newbie
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Re: Solving a geometric problem.

    I had a think and I thought that a simpler way of thinking of the problem is in the scenario of a pool table where you're trying to find where it hits the side on the first bounce (assuming there's no pockets and the balls has a radius of 1).

  6. #5
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Solving a geometric problem.

    If you convert your angle into radians, and take the tangent, then you're looking for the intersection of the line: y - posY = tan(angle)*(x-posX) with the walls. You should have an intersection with two walls, the correct wall will be determined by the angle (firing up/down or left/right)
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 12-18-2010, 12:06 AM
  2. Need help in solving this error!
    By xuele91 in forum C# Programming
    Replies: 0
    Last Post: 06-30-2010, 10:02 PM
  3. C: Problem with solving problem
    By rakche in forum C and C++
    Replies: 15
    Last Post: 03-28-2010, 01:24 PM
  4. heeelp with solving a problem
    By imapwnulol in forum Pascal and Delphi
    Replies: 3
    Last Post: 09-25-2007, 09:01 AM

Tags for this Thread

Bookmarks

Posting Permissions

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