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
Tried it? Did this program work on your calculator?
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.
TI-84 Plus CE Python · screen preview
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
- Enter A, B, and C for the line, then the point's x and y.
- The program shows the top and bottom of the fraction and then the distance.
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
- Rewrite the line so everything is on one side first: y = 2x + 1 becomes 2x - y + 1 = 0.
- Keep the sign of C. In 3x + 4y - 5 = 0, C is -5.
- A distance of 0 means the point is on the line.
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
"""DuckieDai Point-Line Distance for TI-84 Plus CE Python."""from math import sqrtdef duckiedai_intro(program_name, wait=True):"""Show the reusable DuckieDai program opening."""title = program_name[:16]empty = 16 - len(title)left = empty // 2right = empty - leftprint("+----------------------+")print("| " + " " * left + title + " " * right + " |")print("| |")print("| __ |")print("| ___(o )> quack! |")print("| \\ <_. ) |")print("| `---' |")print("| by DuckieDai |")print("+----------------------+")print("Loading...")if wait:input("Press enter to start ")print("\n" * 6)def number(prompt):"""Allow positive, negative, or zero values."""while True:try:value = float(input(prompt))if value > -1e100 and value < 1e100:return valueexcept ValueError:passprint("Enter a valid number.")def get_line():"""Get valid coefficients for Ax + By + C = 0."""while True:print("LINE:")print("Ax + By + C = 0")print()A = number("A: ")B = number("B: ")C = number("C: ")if A != 0 or B != 0:return A, B, Cprint()print("INVALID LINE")print("A and B cannot")print("both be zero.")print()def point_line_distance(A, B, C, x0, y0):"""Return perpendicular distance from point to line."""numerator = abs(A * x0 +B * y0 +C)denominator = sqrt(A ** 2 +B ** 2)distance = numerator / denominatorreturn numerator, denominator, distancedef main():duckiedai_intro("POINT-LINE DIST")print("POINT TO LINE")print("DISTANCE")print()print("Line form:")print("Ax + By + C = 0")print()print("Formula:")print("|A*x0+B*y0+C|")print("----------------")print("sqrt(A^2+B^2)")print()A, B, C = get_line()print()print("POINT (x0, y0)")print()x0 = number("x0: ")y0 = number("y0: ")numerator, denominator, distance = \point_line_distance(A, B, C, x0, y0)print()print("Using:")print("d = |A*x0+B*y0+C|")print(" /sqrt(A^2+B^2)")print()print("Top =")print(str(numerator))print()print("Bottom =")print(str(denominator))print()print("ANSWER")print("Distance =")print(str(distance))print("units")if distance == 0:print()print("Point lies on")print("the line.")print()print("DuckieDai says: done!")# TI-Python imports the selected AppVar rather than# setting __name__ to main.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
- 1.0.0 — current version, published . Download this reviewed version
Related learning
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.