Showing posts with label rectangle. Show all posts
Showing posts with label rectangle. Show all posts

Sunday, July 7, 2024

Numworks: Drawing Simple Shapes with Pyplot

 Numworks: Drawing Simple Shapes with Pyplot


Welcome to a special edition of our blog.


The goal of today’s blog is provide templates to draw simple shapes such as ellipses, circles, rectangles, squares, equilateral triangles, and 45-45-90 right triangles. Adjust the position, screen size, and colors as you see fit.


The module is used is pyplot.



Ellipses and Circles with drawellipse.py


Draw an ellipse given the length of x and y radii. If x and y are equal, a circle is drawn. The screen is set up to fit the proportion of the 320 x 220 screen. The vertical axis ranges from y = -44 to y = 44 while the horizontal axis ranges from x = -64 to x = 64. The ellipse is centered at (0,0).


Numworks script: https://my.numworks.com/python/ews31415/drawellipse


Script: drawellipse.py


from math import *
from matplotlib.pyplot import *

print("Draw an ellipse\nusing pyplot")
a=eval(input("x axis? "))
b=eval(input("y axis? "))

# set axis
axis((-64,64,-44,44))

# set points
tl=[i/128*2*pi for i in range(129)]
xl=[a*cos(i) for i in tl]
yl=[b*sin(i) for i in tl]

# draw the ellipse
c='purple'
plot(xl,yl,c)
show()




Rectangles and Squares with drawrect.py


Draw a rectangle given its horizontal length (h) and vertical length (v). If the horizontal and vertical lengths are equal, a square is drawn. The rectangle is centered at (0, 0). The screen is set up to fit the proportion of the 320 x 220 screen. The vertical axis ranges from y = -44 to y = 44 while the horizontal axis ranges from x = -64 to x = 64.


Numworks script: https://my.numworks.com/python/ews31415/drawrect


Script: drawrect.py


from math import *
from matplotlib.pyplot import *

print("Draw a rectangle\nusing pyplot")
h=eval(input("horiz. length? "))
v=eval(input("vert. length? "))

# set axis
axis((-64,64,-44,44))

# set points
xl=[-h/2,h/2,h/2,-h/2,-h/2]
yl=[v/2,v/2,-v/2,-v/2,v/2]

# color
c='green'

# draw rectangle
plot(xl,yl,c)
show()




Equilateral Triangles with drawtrieq.py


Draws an equilateral (60-60-60) triangle. Enter the length of the side (s). The base is set on the x-axis. The screen is set up to fit the proportion of the 320 x 220 screen. The vertical axis ranges from y = -44 to y = 44 while the horizontal axis ranges from x = -64 to x = 64.


Numworks script: https://my.numworks.com/python/ews31415/drawtrieq


Script: drawtrieq.py


from math import *
from matplotlib.pyplot import *

print("Draw an equilateral triangle\nusing pyplot")
s=eval(input("side length? "))

# set axis
axis((-64,64,-44,44))

# set points
t=s*sqrt(3)/2
xl=[-s/2,s/2,0,-s/2]
yl=[0,0,t,0]

# draw the triangle
c='brown'
plot(xl,yl,c)
show()




45-45-90 Degree Right Triangles with drawtrit.py


Draws an 45-45-90 degree right triangle. Enter the length of the one of the legs (s), not the hypotenuse. The base is set on the x-axis. The screen is set up to fit the proportion of the 320 x 220 screen. The vertical axis ranges from y = -44 to y = 44 while the horizontal axis ranges from x = -64 to x = 64.


Numworks Script: https://my.numworks.com/python/ews31415/drawtrirt


Script: drawtrit.py


from math import *
from matplotlib.pyplot import *

print("Draw a 45-45-90 triangle\nusing pyplot")
s=eval(input("short length? "))

# set axis
axis((-64,64,-44,44))

# set points
xl=[-s/2,s/2,-s/2,-s/2]
yl=[0,0,s,0]

# draw the triangle
c='blue'
plot(xl,yl,c)
show()




Enjoy and I hope you find these scripts useful in your drawing scripts.


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.

Saturday, February 1, 2020

TI-59: Geometric Areas

TI-59: Geometric Areas



Introduction

The program calculates areas of planar geometric shapes.  The following user keys are defined:

A:  Enter A or radius.

B:  Enter B

C:  Enter C

D:  Display the total area

E:  Clear the total area

A':  Calculate the area of an Ellipse:  π*A*B.  For a circle, A = B

B':  Calculate the area of a Rectangle:  A*B.  For a square, A = B

C':  Calculate the area of a Triangle using Heron's Formula. 
S = (A + B + C)/2; √(S * (S - A) * (S - B) * (S - C))

D':  Calculate the area of Sector of a Circle:  π*B°*A^2/360
A:  radius, B: angle in degrees

E':  Calculate the area of a Regular Polygon:  (B * A^2)/(4 * tan(180°/B))
A:  length of a side, B:  number of sides (degrees)

Each calculation will add to the total area.

Memory Registers:

R01:  A
R02:  B
R03:  C
R04:  total area
R05:  S = (A + B + C)/2

The program is for the TI-58C, TI-58, TI-59, their emulators, and TI-66.

TI-59 Program:  Geometry Areas

000 76 LBL
001 11 A
002 42 STO
003 01 01
004 91 R/S
005 76 LBL
006 12 B
007 42 STO
008 02 02
009 91 R/S
010 76 LBL
011 13 C
012 42 STO
013 03 03
014 91 R/S
015 76 LBL
016 14 D
017 43 RCL
018 04 04
019 91 R/S
020 76 LBL
021 15 E
022 25 CLR
023 42 STO
024 04 04
025 91 R/S
026 76 LBL
027 16 A'
028 89 PI
029 65 *
030 43 RCL
031 01 01
032 65 *
033 43 RCL
034 02 02
035 95 =
036 44 SUM
037 04 04
038 91 R/S
039 76 LBL
040 17 B'
041 43 RCL
042 01 01
043 65 *
044 43 RCL
045 02 02
046 95 =
047 44 SUM
048 04 04
049 91 R/S
050 76 LBL
051 18 C'
052 53 (
053 43 RCL
054 01 01
055 85 +
056 43 RCL
057 02 02
058 85 +
059 43 RCL
060 03 03
061 54 )
062 55 /
063 02 2
064 95 =
065 42 STO
066 05 05
067 65 *
068 53 (
069 43 RCL
070 05 05
071 75 -
072 43 RCL
073 01 01
074 54 )
075 65 *
076 53 (
077 43 RCL
078 05 05
079 75 -
080 43 RCL
081 02 02
082 54 )
083 65 *
084 53 (
085 43 RCL
086 05 05
087 75 -
088 43 RCL
089 03 03
090 54 )
091 95 =
092 34 SQRT
093 44 SUM
094 04 04
095 91 R/S
096 76 LBL
097 19 D'
098 60 DEG
099 89 PI
100 65 *
101 43 RCL
102 02 02
103 65 *
104 43 RCL
105 01 01
106 33 X²
107 55 /
108 03 3
109 06 6
110 00 0
111 95 =
112 44 SUM
113 04 04
114 91 R/S
115 76 LBL
116 10 E'
117 53 (
118 01 1
119 08 8
120 00 0
121 55 /
122 43 RCL
123 02 02
124 54 )
125 60 DEG
126 30 TAN
127 65 *
128 04 4
129 95 =
130 35 1/X
131 65 *
132 43 RCL
133 02 02
134 65 *
135 43 RCL
136 01 01
137 33 X²
138 95 =
139 44 SUM
140 04 04
141 91 R/S

Example

5 [ A ]  6 [  B ]

[2nd] [ A' ]   Result:  94.24777961  (area of an ellipse with A = 5, B = 6)

[2nd] [ B' ]  Result:  30  (area of a rectangle with A = 5, B = 6)

9 [ C ]

[2nd] [ C' ]  Result: 14.14213562  (area of a triangle with A = 5, B = 6, C = 9)

9 [ A ] 60 [ B ]

[2nd] [ D' ]  Result: 42.41150082 (area of a circular sector A = 9, B = 60°)

9 [ A ] 8 [ B ]

[2nd] [ E' ]  Result:  391.1025971 (area of a polygon with a side length of 9 and 8 sides)

[ D ]  Total Area:  571.9040132

[ E ] clears total area

Eddie

All original content copyright, © 2011-2020.  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.

Numworks (Python): Parallelograms Described by Vectors

Numworks (Python): Parallelograms Described by Vectors Introduction The script drawpgram.py draws a parallelogram constructed by ...