Hidden WordScanner
Private scans · No account required

DuckieDai Vector Dot Product and Angle

Calculate dot product, magnitudes, angle, and angle class for 2D or 3D vectors.

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

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.

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 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

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

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

Download .py

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

  1. """DuckieDai Vector Angle for TI-84 Plus CE Python."""
  2. from math import sqrt, acos, degrees
  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 safe_acos(value):
  33. """Protect acos from floating-point rounding."""
  34. if value > 1:
  35. value = 1
  36. if value < -1:
  37. value = -1
  38. return acos(value)
  39. def magnitude(x, y, z=0):
  40. """Return vector magnitude."""
  41. return sqrt(
  42. x ** 2 +
  43. y ** 2 +
  44. z ** 2
  45. )
  46. def main():
  47. duckiedai_intro("VECTOR ANGLE")
  48. print("VECTOR DOT PRODUCT")
  49. print("& ANGLE")
  50. print()
  51. print("1. 2D vectors")
  52. print("2. 3D vectors")
  53. print()
  54. choice = input("Choose 1 or 2: ")
  55. print()
  56. # ==========================================
  57. # 2D VECTOR INPUT
  58. # ==========================================
  59. if choice == "1":
  60. print("VECTOR u")
  61. ux = number("ux: ")
  62. uy = number("uy: ")
  63. uz = 0
  64. print()
  65. print("VECTOR v")
  66. vx = number("vx: ")
  67. vy = number("vy: ")
  68. vz = 0
  69. # ==========================================
  70. # 3D VECTOR INPUT
  71. # ==========================================
  72. elif choice == "2":
  73. print("VECTOR u")
  74. ux = number("ux: ")
  75. uy = number("uy: ")
  76. uz = number("uz: ")
  77. print()
  78. print("VECTOR v")
  79. vx = number("vx: ")
  80. vy = number("vy: ")
  81. vz = number("vz: ")
  82. else:
  83. print("Invalid choice.")
  84. print()
  85. print("DuckieDai says: done!")
  86. return
  87. # ==========================================
  88. # VECTOR MAGNITUDES
  89. # ==========================================
  90. mag_u = magnitude(
  91. ux, uy, uz
  92. )
  93. mag_v = magnitude(
  94. vx, vy, vz
  95. )
  96. # Angle is undefined if either vector
  97. # has zero magnitude.
  98. if mag_u == 0 or mag_v == 0:
  99. print()
  100. print("ANGLE UNDEFINED")
  101. print()
  102. print("A zero vector has")
  103. print("no direction.")
  104. print()
  105. print("DuckieDai says: done!")
  106. return
  107. # ==========================================
  108. # DOT PRODUCT
  109. #
  110. # u dot v =
  111. # ux*vx + uy*vy + uz*vz
  112. # ==========================================
  113. dot = (
  114. ux * vx +
  115. uy * vy +
  116. uz * vz
  117. )
  118. # ==========================================
  119. # ANGLE
  120. #
  121. # cos(theta) =
  122. # dot / (|u|*|v|)
  123. # ==========================================
  124. cos_theta = (
  125. dot /
  126. (mag_u * mag_v)
  127. )
  128. theta = degrees(
  129. safe_acos(cos_theta)
  130. )
  131. # ==========================================
  132. # RESULTS
  133. # ==========================================
  134. print()
  135. print("Using:")
  136. print("u dot v /")
  137. print("(|u|*|v|)")
  138. print()
  139. print("DOT PRODUCT")
  140. print("u dot v =")
  141. print(str(dot))
  142. print()
  143. print("MAGNITUDES")
  144. print("|u| = " + str(mag_u))
  145. print("|v| = " + str(mag_v))
  146. print()
  147. print("cos(theta) =")
  148. print(str(cos_theta))
  149. print()
  150. print("ANGLE")
  151. print("theta =")
  152. print(str(theta))
  153. print("degrees")
  154. print()
  155. # ==========================================
  156. # CLASSIFY ANGLE
  157. # ==========================================
  158. tolerance = 0.0000001
  159. if abs(dot) < tolerance:
  160. print("Vectors are")
  161. print("PERPENDICULAR.")
  162. elif dot > 0:
  163. print("Angle is ACUTE.")
  164. else:
  165. print("Angle is OBTUSE.")
  166. print()
  167. print("DuckieDai says: done!")
  168. # TI-Python imports the selected AppVar rather than
  169. # setting __name__ to main.
  170. 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

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.