miércoles, 15 de agosto de 2018

Some Polygonal Spirals

Polygonal Spirals

According with Oxford Advanced Genie Dictionary, a spiral is a shape or design, consisting of a continuous curved line that winds around a central point, with each curve further away from the centre.

In what follows there is a sample of spirals made of regular polygonal lines. Each one is associated with a regular polygon. As the number of sides increases it can be seen that the shape  tends to be a spiral in the sense of above definition.

In what follows some polygonal spirals are drawn using logo programs in Python 3.7 language. This program must be previously installed.


Triangular Spiral


# triang-spiral

from turtle import*
mode('logo')

for i in range(0, 30):     
    fd(10+4*i),lt(120)
Terminator


Square Spiral

# sqr-spiral
from turtle import*
mode('logo')

for i in range(0, 30):     
    fd(10+4*i),lt(90)
Terminator


Pentagon Spiral

#pent-spiral
from turtle import*
mode('logo')

for i in range(0, 30):     
    fd(10+4*i),lt(72)
Terminator






Hexagon Spiral

# hex-spiral
from turtle import*
mode('logo')

for i in range(0, 30):     
    fd(10+4*i),lt(60)
Terminator






Octagon Spiral

# octo-spiral
from turtle import*
mode('logo')

for i in range(0, 30):     
    fd(10+4*i),lt(45)
Terminator







Decagon Spiral

# deca-spiral
from turtle import*
mode('logo')

for i in range(0, 30):     
    fd(10+4*i),lt(36)
Terminator







20 Spiral

(From a regular 20 sides polygon)

# 20-spiral
from turtle import*
mode('logo')

for i in range(0, 30):     
    fd(10+i),lt(18)
Terminator




30 Spiral 

(From a regular 30 sides polygon)

# 30-spiral
from turtle import*
mode('logo')

for i in range(0, 50):     
    fd(5+.5*i),lt(12)
Terminator






The following program can be used to resume the above programs, giving particular values for 'n'

As it can be seen, the numbers 'k' in 'range(0, k)'  can be changed to obtain different sizes.

# poly-siyral
from turtle import*
mode('logo')
#n={3,4,5,8,9,10,12,20}

def polyspiral(n):
    for i in range(0, 30):   
        fd(10+4*i)
        lt(360//n)
#Replace 'n' in the following for a particular value
polyspiral(n)
             
Terminator

martes, 26 de junio de 2018

Some Regular Star Polygons

Regular Polygons and Star Polygons 

A  regular star polygon is a polygonal line whose vertices are vertices of a regular polygon. Their sides are line segments joining vertices of a regular polygon, skipping one or more of them, clockwise or counterclockwise.

The following are samples of star polygons made with logo programs in Python language.
The 3.7 Python program must be previously installed .

# 5-reg-star
from turtle import*
mode('logo')
for i in range(5):
    fd(100),lt(216)
Terminator

# 7-reg-star(1)
from turtle import*
mode('logo')
for i in range(7):
    fd(100),rt(102.9)
Terminator




# 7-reg-star(2)
from turtle import*
mode('logo')
for i in range(7):
    fd(100),rt(154.3)
Terminator

# 8-reg-star
from turtle import*
mode('logo')
for i in range(8):
    fd(100),rt(135)
Terminator

# 9-reg-star(1)
from turtle import*
mode('logo')
for i in range(9):
    fd(70),rt(80)
Terminator


# 9-reg-star(2)
from turtle import*
mode('logo')
for i in range(9):
    fd(70),rt(160)
Terminator


# 10-reg-star
from turtle import*
mode('logo')
for i in range(10):
    fd(100),rt(108)
Terminator




# 12-reg-star
from turtle import*
mode('logo')
for i in range(12):
    fd(100),rt(150)
Terminator






lunes, 25 de junio de 2018

Some Regular Polygons

Drawing Regular Polygons

In what follows some regular polygons are drawn using logo programs in Python 3.7 language. This program must be previously installed.

#Equilateral triangle
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(3):
    fd(100),lt(120)


 Terminator





#Square
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(4):
    fd(100), lt(90)
Terminator






# Regular Pentagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(5):
    fd(100), lt(72)
Terminator


#Regular Hexagon.
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(6):
    fd(50),lt(60)
Terminator


#Regular Octagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(8):
    fd(50),lt(45)
Terminator

#Regular Nonagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(10):
    fd(50),lt(40)
Terminator



#Regular Decagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(10):
    fd(50),lt(36)
Terminator


#Regular Dodecagon
import cmd,sys
from turtle import*
color('black')
mode('logo')
for i in range(12):
    fd(50),lt(30)
Terminator

miércoles, 6 de junio de 2018

Integer Pythagorean Triples


Pythagorean Triples

With positive integers

The following is a Python 3.7 program. It must be previously installed.

print('Type a positive integer')
integer=input()
integer=int(integer)
for a in range(1,integer):
    for b in range(1, integer):
        for c in range(1, integer):
            if a**2+b**2==c**2:
                if a <b<c                   
                    print([a,b,c])


Example (1): For numbers not greater than 8

Type a positive integer
8
[3, 4, 5]

Example (2): For numbers not grater than 30

Type a positive integer
30
[3, 4, 5]
[5, 12, 13]
[6, 8, 10]
[7, 24, 25]
[8, 15, 17]
[9, 12, 15]
[10, 24, 26]
[12, 16, 20]
[15, 20, 25]
[20, 21, 29]

Divisors of a positive integer

All the divisors...

of a positive integer

The following is a 3.7 Python program. It has to be previously installed

#Divisors of a positive integer
x=int(input('Type a positive integer  '))
for j in range(1,x+1):
    if x//j==x/j:
        print(j,end=',')
        j=j+1

Example (1): For 3780

Type a positive integer  3780
1,2,3,4,5,6,7,9,10,12,14,15,18,20,21,27,28,30,35,36,42,45,54,60,63,70,84,90,105,108,126,135,140,180,189,210,252,270,315,378,420,540,630,756,945,1260,1890,3780,

Example (2): For 3781

Type a positive integer  3781
1,19,199,3781,

Example 3: For 3701

Type a positive integer  3701
1,3701,

martes, 5 de junio de 2018

Fractions and decimals

Fractions and decimal representation

The following is a Python 3.7. It must be previously installed,

#Fractions and decimal representation
print('Type integer part and no periodical part, without decimal point')
a=int(input())
print('Type the same figures and add the figures of the first period')
b=int(input())
numerator=b-a
print('Type 9 a number of times equal to number of figures in the period')
print('and type 0 a number of times equal to number of figures')
print('before the periodic part, and to the right of decimal point')
denominator=int(input())
print('The generator fraction is',numerator,'/',denominator)

Example (1): Given 25.36124242424...

Type integer part and no periodical part, without decimal point
25361
Type the same figures and add the figures of the first period
2536124
Type 9 a number of times equal to number of figures in the period
and type 0 a number of times equal to number of figures
before the periodic part, and to the right of decimal point
99000
The generator fraction is 2510763 / 99000
or, simplyfying, 836921/33000

Example(2): Given 4.23232323...

Type integer part and no periodical part, without decimal point
4
Type the same figures and add the figures of the first period
423
Type 9 a number of times equal to number of figures in the period
and type 0 a number of times equal to number of figures
before the periodic part, and to the right of decimal point
99
The generator fraction is 419 / 99

lunes, 4 de junio de 2018

Three points for a plane

Plane determined by...

three points


The following is a Python 3.7 program. It must be previously installed.

#Equation of a plane, (Ax + By + Cz + D = 0) known three of its points
#(a, b, c), (d, e, f,), (g, h, t)

print('type, one at a time, a, b, c, d, e, f, g, h, t')

a = float(input())
b = float(input())
c = float(input())
d = float(input())
e = float(input())
f = float(input())
g = float(input())
h = float(input())
t = float(input())

A=b*f+c*h+e*t-f*h-c*e-b*t
B=-a*f-c*g-d*t+f*g+c*d+a*t
C=a*e+b*g+d*h-b*d-e*g-a*h
D=a*e*t+b*f*g+c*d*h-c*e*g-b*d*t-a*f*h
    
print('lthe equation of the plane is')
print(A,'x+',B,'y+',C,'z+',D,'=0')


Example (1). For (-3, 1, -2), (5, -4, -1), (4, 5, 2)

-3
1
-2
5
-4
-1
4
5
2
the equation of the plane is
-24.0 x+ -25.0 y+ 67.0 z+ -87.0 =0

This equation could be rewritten as 24x + 25y - 67z -87 = 0.

Example(2): For (2, 3, 1), (4, -2, 5), (6, 1, 6)

2
3
1
4
-2
5
6
1
6
the equation of the plane is
-17.0 x+ 6.0 y+ 16.0 z+ 0.0 =0
This equation could be rewritten as 17x - 6y -16z = 0  (The point (0, 0, 0) is in the plane)

Example (3):For (1, -2, 5), (13, 7, 11), 37, 25, 23)

1
-2
5
13
7
11
37
25
23
1
-2
5
13
7
11
37
25
23
the equation of the plane is
0.0 x+ 0.0 y+ 0.0 z+ 0.0 =0

That is, 0x + 0y + 0z + 0 = 0

In this case, the three given points are collinear