Showing posts with label ellipses. Show all posts
Showing posts with label ellipses. Show all posts

Sunday, August 4, 2024

TI-84 Plus CE Python: Drawing Shapes with the ti_plotlib module

 TI-84 Plus CE Python: Drawing Shapes with the ti_plotlib module


Introduction


Here are four scripts to draw shapes:


RECT8: rectangles and squares centered at (0, 0)

ELLIPSE8: ellipses and circles centered at (0, 0)

POLYGON8: polygons given the vertex points and number of vertices

INVFUNC8: draws a function f(x) and it’s inverse f^-1(x). Define the function is defined in the f(x) subroutine in the program.


The plot window is sized in sync with the TI-84’s screen size (320 pixels x 220 pixels) so that squares look like squares and circles look like circles. The window parameters are set as such:

Xmin = -16, Xmax = 16

Ymin = -10.5, Ymax = 10.5



TI-84 PLUS CE Python Script: RECT8.py





import ti_plotlib as plt

from math import *


# draw an rectangle using ti_plqtlib

# get parameters

print("Press [clear] to \nexit the graph.")

print("x:[-16,16] \ny:[-10.5,10.5]")

a=eval(input("horiz. length? "))

b=eval(input("vert. length? "))


# plot routine

plt.cls()

plt.title("Rectangle")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.grid(1,1,"dot")


# color: blue

plt.color(0,0,192)


# pen size

plt.pen("medium","solid")


plt.line(-a/2,b/2,a/2,b/2,"")

plt.line(-a/2,-b/2,a/2,-b/2,"")

plt.line(-a/2,-b/2,-a/2,b/2,"")

plt.line(a/2,-b/2,a/2,b/2,"")


plt.show_plot()


TI-84 PLUS CE Python Script: ELLIPSE8.py





import ti_plotlib as plt

from math import *


# draw an ellipse using ti_plqtlib

# get parameters

print("Press [clear] to \nexit the graph.")

print("x:[-16,16] \ny:[-10.5,10.5]")

a=eval(input("x axis? "))

b=eval(input("y axis? "))


# plot routine

plt.cls()

plt.title("Ellipse")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.pen("medium","solid")

plt.grid(1,1,"dot")


# color: green

plt.color(0,192,0)


for i in range(128):

  x=a*cos(i*pi/64)

  y=b*sin(i*pi/64)

  plt.plot(x,y,"o")


plt.show_plot()



TI-84 PLUS CE Python Script: POLYGON8.py





import ti_plotlib as plt

from math import *


# draw an rectangle using ti_plqtlib

# get parameters

print("Press [clear] to \nexit the graph.")

print("x:[-16,16] \ny:[-10.5,10.5]")


n=int(input("# of vertices? "))

a=eval(input("x1? "))

b=eval(input("y1? "))


x=[a]

y=[b]


for i in range(n-1):

  print("vertex ",i+2)

  c=eval(input("x? "))

  d=eval(input("y? "))

  x.append(c)

  y.append(d)

x.append(a)

y.append(b)



# plot routine

plt.cls()

plt.title("Polygon")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.grid(1,1,"dot")

plt.color(75,0,130)

plt.pen("medium","solid")


for i in range(n):

  x0=x[i]

  y0=y[i]

  x1=x[i+1]

  y1=y[i+1]

  plt.line(x0,y0,x1,y1,"")


plt.show_plot()



TI-84 PLUS CE Python Script: INVFUNC8.py





Define f(x) in the def f(x) function routine. The math module is imported.



import ti_plotlib as plt

from math import *


# f(x) and f**-1(x)

# define f(x)

def f(x):

  return x**2+6


# plot routine

plt.cls()

plt.title("f(x) and its inverse")

plt.window(-16,16,-10.5,10.5)

plt.axes("on")

plt.grid(1,1,"dot")


plt.pen("medium","solid")


for i in range(320):

  x=-16+i*32/320

  y=f(x)

  plt.color(0,0,192)

  plt.plot(x,y,"o")

  plt.color(255,165,0)

  plt.plot(y,x,"o")



plt.show_plot()



Download the four scripts here: https://drive.google.com/file/d/1ELL6mEzMXrIJlOSSFocOZGJTza-kBZoU/view?usp=sharing



Eddie


All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.


Sunday, July 31, 2016

Casio fx-50FH Programs: Ellipses

Casio fx-50FH Programs: Ellipses

Hello everyone!  It is good to be back.  What a crazy year this has been so far.  





Introduction

The programs assume that the center of the ellipse is (0,0).  They can be adopted on the current Casio graphing calculators and fx-5800p as well (some adjustments may be necessary).  

Casio fx-50FH Ellipse Program 1: Area, Eccentricity, Focal Points
(61 steps)

Text after double slash marks (\\) are comments.  

?→X:   \\ radius on X-axis
?→Y:   \\ radius on Y-axis
X≥Y ⇒ Goto 0:
X→B: Y→A: Goto 1:  \\ X ≥ Y 
Lbl 0: X→A: Y→B:   \\ X < Y
Lbl 1: Ï€AB ◢  \\ calculate area
√(1 - B ² ÷ A ²) ◢   \\ calculate eccentricity 
√(A ² - B ²)  \\ focal distance 

Test 1: X = 6.63, Y = 1.86
Area:  38.74149229
Eccentricity: 0.959841462
Focal Distance: 6.36748895
Hence the focal points are (-6.36748895, 0) and (6.36748895, 0)

Test 2: X = 2.99, Y = 5.06
Area: 47.53041189
Eccentricity: 0.806738152
Focal Distance: 4.08209505
Hence the focal points are (0, -4.08209505) and (0, 4.08209505)

Casio fx-50FH Ellipse Program 2: Points on the Ellipse, and distance to center (0,0)
(54 steps)

You specify A, B, and D.  D represents the number of steps.  Degree mode is set. 

?→A: ?→B: ?→D:
Deg: For 0→M To 360 Step 360 ÷ D:  \\ set up loop
M ◢  \\ display angle 
A cos(M) → X ◢   \\ display X coordinate 
B sin(M) → Y ◢  \\ display Y coordinate
√( X ² + Y ² ) ◢  \\ distance to center
Next  \\ end loop

Test: A = 3.25, B = 2.75, D = 6
Results: (angle, X, Y, distance)
0.000, 3.250, 0.000, 3.250
60.000, 1.625, 2.382, 2.883
120.000, -1.625, 2.382, 2.883
180.000, -3.250, 0.000, 3.250
240.000, -1.625, -2.382, 2.883
300.000, 1.625, -2.382, 2.883
360.000, 3.250, 0.000, 3.250

Until next time, 

Eddie


This blog is property of Edward Shore, 2016

Casio fx-50F/Radio Shack EC-4024 Program Collection: October 2026

Casio fx-50F/Radio Shack EC-4024 Program Collection: October 2026 Notes: * The fx-50F/EC-4024 has a 29 step program space betwe...