예제 #1
0
 def test_e_module(self):
     e0 = D
     e1 = rt2(3) * PHI**-1
     e2 = rt2((5 - root5) / 2)
     e3 = (3 - root5) / 2
     e4 = rt2(5 - 2 * root5)
     e5 = 1 / PHI
     tet = Tetrahedron(e0, e1, e2, e3, e4, e5)
     self.assertTrue(1 / 23 > tet.ivm_volume() / 8 > 1 / 24, "Wrong E-mod")
예제 #2
0
 def test_equilateral(self):
     t = Triangle((0, 0), (10, 0), (5, 5 * rt2(3)))
     t.in_radians = False
     self.assertAlmostEqual(t.ABC, 60)
     self.assertAlmostEqual(t.BAC, 60)
     self.assertAlmostEqual(t.ACB, 60)
     self.assertTrue(t.is_equiangular)
예제 #3
0
 def area(self):
     """
     Heron's formula
     """
     s = (self.a + self.b + self.c) / 2
     return rt2(s * (s - self.a) * (s - self.b) *
                (s - self.c))  # Heron's formula
예제 #4
0
 def xyz_area(self):
     """
     Heron's Formula, without the 1/4
     """
     a,b,c = self.a, self.b, self.c
     xyzarea = rt2((a+b+c)* (-a+b+c) * (a-b+c) * (a+b-c))
     return xyzarea
예제 #5
0
파일: tetrabook.py 프로젝트: xue2f/Python5
def volumes():
    book = TetraBook()
    book.radians = False
    print("ALT     IVM     XYZ     Long    Short   AngleL     AngleS")
    for vol in [rt2(x) / rt2_8 for x in range(0, 10)]:
        book.ivm_volume = vol
        xyzvol = (1 / 3) * xyz_base * book.altitude
        # fancy volume formula jibes with simple (1/3 base * height)
        try:
            assert abs(book.xyz_volume - xyzvol) < 0.0001
        except AssertionError:
            print("Error: ", "{:7.5f}  {:7.5f}".format(book.xyz_volume,
                                                       xyzvol))

        print("{:7.5f} {:7.5f} {:7.5f} {:7.5f} {:7.5f} {:9.5f} {:9.5f}".format(
            book.altitude, book.ivm_volume, book.xyz_volume, book.long_edge,
            book.short_edge, book.angle_l, book.angle_s))
예제 #6
0
 def test_ivm(self):
     t = Triangle((-1, 0), (1, 0), (0, rt2(3)))  # book cover
     self.assertAlmostEqual(t.ivm_area, 1.0)
예제 #7
0
 def ivm_area(self):
     return self.area / rt2(3)
예제 #8
0
"""
Euler volume, modified by Gerald de Jong
http://www.grunch.net/synergetics/quadvols.html
Kirby Urner (c) MIT License

See:
http://mathforum.org/kb/thread.jspa?threadID=2836546
for explanation of quadrays, used for some unit tests
"""

from math import sqrt as rt2
from qrays import Qvector, Vector
import sys

S3 = pow(9 / 8, 0.5)
root2 = rt2(2)
root5 = rt2(5)


class Tetrahedron:
    """
    Takes six edges of tetrahedron with faces
    (a,b,d)(b,c,e)(c,a,f)(d,e,f) -- returns volume
    if ivm and xyz
    """
    def __init__(self, a, b, c, d, e, f):
        # a,b,c,d,e,f = [Decimal(i) for i in (a,b,c,d,e,f)]
        self.a, self.a2 = a, a**2
        self.b, self.b2 = b, b**2
        self.c, self.c2 = c, c**2
        self.d, self.d2 = d, d**2
예제 #9
0
 def c(self):
     Ax, Ay = self._Axy
     Bx, By = self._Bxy
     return rt2((Ax - Bx)**2 + (Ay - By)**2)
예제 #10
0
 def test_area_martian3(self):
     qx = Vector((D,0,0)).quadray()
     qy = Vector((R,rt2(3)/2,0)).quadray()
     result = qx.area(qy)
     self.assertAlmostEqual(result, 1, 7)
예제 #11
0
 def ivm_area(self):
     ivmarea = self.xyz_area() * 1/rt2(3)
     return ivmarea
예제 #12
0
파일: tetrabook.py 프로젝트: xue2f/Python5
 def _short(self):
     return rt2(6 - (rt2(12) * rt2(3 - self._altitude**2)))
예제 #13
0
파일: tetrabook.py 프로젝트: xue2f/Python5
 def _long(self):
     return rt2(6 + (rt2(12) * rt2(3 - self._altitude**2)))
예제 #14
0
파일: tetrabook.py 프로젝트: xue2f/Python5
 def short_edge(self, value):
     self._short_edge = value
     self._long_edge = rt2(long_diag**2 - self._short_edge**2)
     self._altitude = self.xyz_volume * rt2_3
예제 #15
0
 def a(self):
     Bx, By = self._Bxy
     Cx, Cy = self._Cxy
     return rt2((Bx - Cx)**2 + (By - Cy)**2)
예제 #16
0
 def b(self):
     Ax, Ay = self._Axy
     Cx, Cy = self._Cxy
     return rt2((Ax - Cx)**2 + (Ay - Cy)**2)
예제 #17
0
 def test_area_earthling2(self):
     vx = Vector((2,0,0))
     vy = Vector((1,rt2(3),0))
     result = vx.area(vy)
     self.assertAlmostEqual(result, 2*rt2(3))    
예제 #18
0
Kirby Urner (c) MIT License

See:
http://mathforum.org/kb/thread.jspa?threadID=2836546
for explanation of quadrays, used for some unit tests
"""

from math import sqrt as rt2
from qrays import Qvector, Vector
import sys

R = 0.5
D = 1.0

S3 = pow(9 / 8, 0.5)
root2 = rt2(2)
root3 = rt2(3)
root5 = rt2(5)
root6 = rt2(6)
PHI = (1 + root5) / 2.0


class Tetrahedron:
    """
    Takes six edges of tetrahedron with faces
    (a,b,d)(b,c,e)(c,a,f)(d,e,f) -- returns volume
    if ivm and xyz
    """
    def __init__(self, a, b, c, d, e, f):
        # a,b,c,d,e,f = [Decimal(i) for i in (a,b,c,d,e,f)]
        self.a, self.a2 = a, a**2
예제 #19
0
 def test_xyz_area3(self):
     tri = Triangle(D, D, D)
     self.assertEqual(tri.xyz_area(), rt2(3))
예제 #20
0
              "Amod",
              "Bmod",
              "Smod3",
              "Smod",
              "smod3"], dtype=np.unicode),
    name="Shapes")

zeros         = pd.Series(np.zeros((21,)), dtype=np.float64)
volumes_table = pd.DataFrame({"Volumes" : zeros,
                              "Comments": pd.Series(['']*21, 
                                            dtype=np.unicode)
                             })
volumes_table.index = shapes
#%%

φ  = (rt2(5)+1)/2      # golden ratio
S3 = rt2(9/8)          # not to be confused with Smod

Smod = (φ **-5)/2      # home base Smod
smod3 = Smod  * φ**-3  # small s, phi down
Smod3 = Smod  * φ**3   # capital s, phi up
Smod6 = Smod3 * φ**3   # phi up yet again

cubocta = 20
SuperRT = S3 * cubocta

Octa = 4

Emod3 = SuperRT / 120          # Emod phi up
Emod = (rt2(2)/8) * (φ ** -3)  # home base Emod
emod3 = Emod * φ ** -3         # Emod phi down
예제 #21
0
파일: tetrabook.py 프로젝트: xue2f/Python5
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 17 21:41:28 2017

@author: kurner
"""

from math import sqrt as rt2, asin, sin, pi, degrees, radians
from tetravolume import Tetrahedron

# CONSTANTS
phi = (1 + rt2(5)) / 2
rt2_3 = rt2(3)
long_diag = 2 * rt2_3  # cover tip to cover tip, diagonal of rhomb
rt2_8 = rt2(8)
rt2_9 = rt2(9)  # = 3
rt2_6 = rt2(6)  # cover tip to page tip, page vertical
Syn3 = rt2(9 / 8)  # synergetics constant (to 3rd power)
xyz_base = rt2_3


class TetraBook:

    radians = True

    def __init__(self, L=long_diag):
        self.long_edge = L

    @property
    def long_edge(self):
        return self._long_edge