geometry · MIT License
Overview
Calculate dot product, magnitudes, angle, and angle class for 2D or 3D vectors.
- Tested on a TI calculator
- Downloaded 43 times
- Version 1.0.0
- 4772 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.
- Neither vector is the zero vector when calculating an angle.
- Components must remain between -1e100 and 1e100; zero-vector angles are undefined.
- A zero vector cannot produce a direction or angle.
Try the DuckieDai calculator screen
This browser preview calculates the dot product and angle for two 2D vectors. The TI program also supports 3D vectors.
TI-84 Plus CE Python · screen preview
Learn the math
How the dot product and the angle between vectors work
The idea
The dot product multiplies two vectors into a single number that measures how much they point the same way. Combined with the vectors' lengths, it gives the angle between them.
A positive dot product means an acute angle, zero means perpendicular, and negative means obtuse.
The formula
u dot v = ux*vx + uy*vy (+ uz*vz)
cos(theta) = (u dot v)/(|u|*|v|)
u, v- the two vectors
|u|, |v|- their lengths (magnitudes)
theta- the angle between them, in degrees
Using the program
- Choose 1 for 2D vectors or 2 for 3D.
- Enter the components of u, then of v.
- The program shows the dot product, both magnitudes, the cosine, the angle, and whether it is acute, perpendicular, or obtuse.
Worked example
Find the angle between u = (1, 0) and v = (1, 1). Choose 1 and enter 1, 0, 1, and 1.
cos(theta) = 1/(1 x 1.4142) = 0.7071
The program shows u dot v = 1.0, an angle of 45 degrees (printed as 45.00000000000001), and Angle is ACUTE.
Tips and common mistakes
- A zero vector has no direction, so it has no angle with anything.
- The dot product is a number, not a vector.
- Perpendicular vectors always have a dot product of 0.
Where this comes up
Vectors and the dot product appear in precalculus, in physics for work and components, and in the first weeks of linear algebra and multivariable calculus.
Exact reviewed bytes
Source code
"""DuckieDai Vector Angle for TI-84 Plus CE Python."""from math import sqrt, acos, degreesdef 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 safe_acos(value):"""Protect acos from floating-point rounding."""if value > 1:value = 1if value < -1:value = -1return acos(value)def magnitude(x, y, z=0):"""Return vector magnitude."""return sqrt(x ** 2 +y ** 2 +z ** 2)def main():duckiedai_intro("VECTOR ANGLE")print("VECTOR DOT PRODUCT")print("& ANGLE")print()print("1. 2D vectors")print("2. 3D vectors")print()choice = input("Choose 1 or 2: ")print()# ==========================================# 2D VECTOR INPUT# ==========================================if choice == "1":print("VECTOR u")ux = number("ux: ")uy = number("uy: ")uz = 0print()print("VECTOR v")vx = number("vx: ")vy = number("vy: ")vz = 0# ==========================================# 3D VECTOR INPUT# ==========================================elif choice == "2":print("VECTOR u")ux = number("ux: ")uy = number("uy: ")uz = number("uz: ")print()print("VECTOR v")vx = number("vx: ")vy = number("vy: ")vz = number("vz: ")else:print("Invalid choice.")print()print("DuckieDai says: done!")return# ==========================================# VECTOR MAGNITUDES# ==========================================mag_u = magnitude(ux, uy, uz)mag_v = magnitude(vx, vy, vz)# Angle is undefined if either vector# has zero magnitude.if mag_u == 0 or mag_v == 0:print()print("ANGLE UNDEFINED")print()print("A zero vector has")print("no direction.")print()print("DuckieDai says: done!")return# ==========================================# DOT PRODUCT## u dot v =# ux*vx + uy*vy + uz*vz# ==========================================dot = (ux * vx +uy * vy +uz * vz)# ==========================================# ANGLE## cos(theta) =# dot / (|u|*|v|)# ==========================================cos_theta = (dot /(mag_u * mag_v))theta = degrees(safe_acos(cos_theta))# ==========================================# RESULTS# ==========================================print()print("Using:")print("u dot v /")print("(|u|*|v|)")print()print("DOT PRODUCT")print("u dot v =")print(str(dot))print()print("MAGNITUDES")print("|u| = " + str(mag_u))print("|v| = " + str(mag_v))print()print("cos(theta) =")print(str(cos_theta))print()print("ANGLE")print("theta =")print(str(theta))print("degrees")print()# ==========================================# CLASSIFY ANGLE# ==========================================tolerance = 0.0000001if abs(dot) < tolerance:print("Vectors are")print("PERPENDICULAR.")elif dot > 0:print("Angle is ACUTE.")else:print("Angle is OBTUSE.")print()print("DuckieDai says: done!")# TI-Python imports the selected AppVar rather than# setting __name__ to main.main()
- Filename
VECDOT.py- Size
- 4772 bytes
- SHA-256
ce10c3625e3880468361fd5b292e2d982ecf2ee49a0fba89e9e6959eccb7dcc8
Usage
Inputs
- Two 2D or 3D vectors with finite components
Outputs
- Dot product, magnitudes, angle in degrees, and perpendicular/acute/obtuse classification
Units: Both vectors must use compatible component units.
Assumptions and limitations
Assumptions
- Neither vector is the zero vector when calculating an angle.
Constraints
- Components must remain between -1e100 and 1e100; zero-vector angles are undefined.
Known failures
- A zero vector cannot produce a direction or angle.
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 vector dot product angle program runs on the physical calculator.
- Dependencies
- math
- Suggested calculator name
VECDOT— 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 VECDOT 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.