Hidden WordScanner
Private scans · No account required

DuckieDai Point-to-Line Distance

Calculate perpendicular distance from a point to a line written as Ax + By + C = 0.

geometry · MIT License

Overview

Calculate perpendicular distance from a point to a line written as Ax + By + C = 0.

  • Tested on a TI calculator
  • Downloaded 43 times
  • Version 1.0.0
  • 3045 bytes
  • Uses math

Before you run it

  • TI-84 Plus CE Python · tested on OS 5.8.3, Python App 5.8.3.0048
  • TI Connect CE .py conversion to a Python AppVar in RAM; owner physically verified the supplied program.
  • The line is represented by Ax + By + C = 0.
  • A and B cannot both be zero; entered values must remain between -1e100 and 1e100.
  • An all-zero A and B pair is rejected.

Try the DuckieDai calculator screen

This browser preview applies the perpendicular-distance formula to one line and point.

JavaScript is required for the optional browser simulation. Source viewing and downloading remain available without it.

Simulation boundary: This preview uses a reviewed browser adapter. It does not execute the downloaded Python and does not prove TI-Python or calculator compatibility.

Learn the math

How the distance from a point to a line works

The idea

The distance from a point to a line means the shortest one: straight across, at a right angle to the line. A single formula gives it when the line is written in general form.

The formula

d = |A*x0 + B*y0 + C| / sqrt(A^2 + B^2)

A, B, C
coefficients of the line Ax + By + C = 0
x0, y0
coordinates of the point
d
perpendicular distance

Using the program

Worked example

Find the distance from the point (2, 1) to the line 3x + 4y - 5 = 0. Enter 3, 4, -5, then 2 and 1.

d = |3 x 2 + 4 x 1 - 5| / sqrt(9 + 16) = 5/5

The program shows Top = 5.0, Bottom = 5.0, and Distance = 1.0 units.

Tips and common mistakes

Where this comes up

It comes up in the coordinate geometry unit of geometry and algebra 2, and in precalculus and linear algebra when distances and projections are introduced.

Exact reviewed bytes

Source code

Download .py

View source below, copy it when JavaScript is available, or download the exact .py bytes.

  1. """DuckieDai Point-Line Distance for TI-84 Plus CE Python."""
  2. from math import sqrt
  3. def duckiedai_intro(program_name, wait=True):
  4. """Show the reusable DuckieDai program opening."""
  5. title = program_name[:16]
  6. empty = 16 - len(title)
  7. left = empty // 2
  8. right = empty - left
  9. print("+----------------------+")
  10. print("| " + " " * left + title + " " * right + " |")
  11. print("| |")
  12. print("| __ |")
  13. print("| ___(o )> quack! |")
  14. print("| \\ <_. ) |")
  15. print("| `---' |")
  16. print("| by DuckieDai |")
  17. print("+----------------------+")
  18. print("Loading...")
  19. if wait:
  20. input("Press enter to start ")
  21. print("\n" * 6)
  22. def number(prompt):
  23. """Allow positive, negative, or zero values."""
  24. while True:
  25. try:
  26. value = float(input(prompt))
  27. if value > -1e100 and value < 1e100:
  28. return value
  29. except ValueError:
  30. pass
  31. print("Enter a valid number.")
  32. def get_line():
  33. """Get valid coefficients for Ax + By + C = 0."""
  34. while True:
  35. print("LINE:")
  36. print("Ax + By + C = 0")
  37. print()
  38. A = number("A: ")
  39. B = number("B: ")
  40. C = number("C: ")
  41. if A != 0 or B != 0:
  42. return A, B, C
  43. print()
  44. print("INVALID LINE")
  45. print("A and B cannot")
  46. print("both be zero.")
  47. print()
  48. def point_line_distance(A, B, C, x0, y0):
  49. """Return perpendicular distance from point to line."""
  50. numerator = abs(
  51. A * x0 +
  52. B * y0 +
  53. C
  54. )
  55. denominator = sqrt(
  56. A ** 2 +
  57. B ** 2
  58. )
  59. distance = numerator / denominator
  60. return numerator, denominator, distance
  61. def main():
  62. duckiedai_intro("POINT-LINE DIST")
  63. print("POINT TO LINE")
  64. print("DISTANCE")
  65. print()
  66. print("Line form:")
  67. print("Ax + By + C = 0")
  68. print()
  69. print("Formula:")
  70. print("|A*x0+B*y0+C|")
  71. print("----------------")
  72. print("sqrt(A^2+B^2)")
  73. print()
  74. A, B, C = get_line()
  75. print()
  76. print("POINT (x0, y0)")
  77. print()
  78. x0 = number("x0: ")
  79. y0 = number("y0: ")
  80. numerator, denominator, distance = \
  81. point_line_distance(
  82. A, B, C, x0, y0
  83. )
  84. print()
  85. print("Using:")
  86. print("d = |A*x0+B*y0+C|")
  87. print(" /sqrt(A^2+B^2)")
  88. print()
  89. print("Top =")
  90. print(str(numerator))
  91. print()
  92. print("Bottom =")
  93. print(str(denominator))
  94. print()
  95. print("ANSWER")
  96. print("Distance =")
  97. print(str(distance))
  98. print("units")
  99. if distance == 0:
  100. print()
  101. print("Point lies on")
  102. print("the line.")
  103. print()
  104. print("DuckieDai says: done!")
  105. # TI-Python imports the selected AppVar rather than
  106. # setting __name__ to main.
  107. main()
Filename
PTLINE.py
Size
3045 bytes
SHA-256
01930d1a4a1ad79ed564c62296cec16f6e3cb7b371ec0c98dd7957042ee0d4ff

Usage

Inputs

  • Line coefficients A, B, and C
  • Point coordinates x0 and y0

Outputs

  • Perpendicular distance and an on-line notice when the distance is zero

Units: Coordinates and coefficients must use one consistent coordinate system.

Assumptions and limitations

Assumptions

  • The line is represented by Ax + By + C = 0.

Constraints

  • A and B cannot both be zero; entered values must remain between -1e100 and 1e100.

Known failures

  • An all-zero A and B pair is rejected.

Compatibility and review

Review status
Tested on a TI calculator
Tested on
TI-84 Plus CE Python; OS 5.8.3; Python App 5.8.3.0048; exact source owner-tested through TI Connect CE
What happened
Owner confirmed the supplied point to line distance program runs on the physical calculator.
Dependencies
math
Suggested calculator name
PTLINE — you can give it another valid, unique name when you transfer it
Desktop test cases
Not available for this interactive-only source

This exact source auto-launches an interactive calculator session, so compatibility evidence comes from the recorded physical-device review rather than an importable desktop fixture.

Transfer and launch

Download the .py file, send it to your calculator with TI Connect CE as PTLINE or another name, then open the Python App and try the worked example on this page first.

Full installation and troubleshooting guide. Check your teacher's or exam's rules before using any program.

Version history

Did a DuckieDai program help with your homework? Every program here is free. If you would like to say thanks, you can leave a tip on Cash App ($duckiedai214) or read what tips pay for.

Independent compatibility resource: Hidden Word Scanner is independent and is not affiliated with or endorsed by Texas Instruments. TI product names describe compatibility only.

Action-count privacy: Successful downloads, preview starts, and preview completions increment same-origin aggregate counters, and so does a Yes or No answer about whether the program worked. Your browser notes that you answered; that note is never sent to the site. No entered values, source text, IP address, account, cookie, device identifier, or fingerprint is stored with these counts.