Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8290697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:53:12+00:00 2026-06-08T12:53:12+00:00

I am implementing a 2D football game. For my pass algorithm, I calculate the

  • 0

I am implementing a 2D football game. For my pass algorithm, I calculate the slope between the passer and reciever with the equation m = (y2-y1)/(x2-x1)

In some conditions x2 and x1 are equal resulting in a divide by zero exception. What should I do in this case?

I did not ask this question on math.stackexchange.com because it’s a programming question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:53:13+00:00Added an answer on June 8, 2026 at 12:53 pm

    Don’t use the slope of a line for this sort of operation, for just the reason you have stumbled across. Use instead the angle of the line from passer to passee. Apply a little trigonometry. If that little trigonometry is beyond you, delete this question, do some work, then post again when you get stuck again.

    EDIT

    I suggest you use trigonometry for 2 reasons.

    1. Because the slope of a line between two points with the same x coordinate is indeterminate. Yes, you could, as the other answer suggests, fiddle around and make the slope a very large value when the x coordinates are the same, but it’s an unnecessary compromise when trigonometry, which will produce an angle whatever the x and y coordinates, is available.
    2. Trigonometry will give you a natural interpretation of the value of the angle from passer to passee. A pass at an angle of 90 degrees (pi/2 radians, though I’m not sure many footballers or fans think of angles in radians during a match) means a cross-field pass (I’m assuming that your y-axis aligns with the long axis of your pitch), a pass at an angle of 180 degrees is a back pass, and so forth.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Implementing the very first scala example I ran into some problems probably tipical for
Implementing a low pass FIR filter, when should one use FFT and IFFT instead
Im implementing a pool billiard game in Java and it all works fine. It
Implementing the basic algorithm using last array as a pivot in Java, is it
When implementing iterator using yield return , is there any difference between returning IEnumerator
While implementing my own IFilter I found that most likely some consumers will require
Im implementing a recursive routine to calculate all the terms of a multinomial expression,
When implementing a graph search algorithm, I needed a priority queue which allowed for
While implementing SOAP webservice accessing, i found there is a wsdl file in some
Implementing a custom Dependency Property on a Framework Element object causes my Visual Studio

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.