# -*- coding: iso-8859-7 -*-
from math import fabs
from varcon import PI2,thanThresholdx
def dpt (gon): # Python guarantees that result has
"Converts an angle (in rads) to normal form (between 0.0 and 2*PI)."
return gon % PI2 # the same sign as PI2 i.e. positive
#def testGon(): # Test code for dpt function
# t = [ (500, 140), (900, 180), (-500, 220), (-800, 280) ]
# for g in t:
# print dpt(g[0] / 180.0 * pi) / pi * 180, "should be", g[1]
def linint(x1, y1, x2, y2, x):
"Linear interpolation with no checking."
return y1 + (y2-y1)/(x2-x1) * (x-x1)
def bilinint(va, ma1, wa1,
ma2, wa2,
vb, mb1, wb1,
mb2, wb2,
v, m):
"""Interpolates for w(w, m) using blinear interpolation.
For dimensionless axial force v=va it is known:
dimensionless moment ma1 -> needs wa1 reinforcement
dimensionless moment ma2 -> needs wa2 reinforcement
For dimensionless axial force v=vb it is known:
dimensionless moment mb1 -> needs wb1 reinforcement
dimensionless moment mb2 -> needs wb2 reinforcement
With these data compute the reinforcment w for v and m.
"""
wa = linint(ma1, wa1, ma2, wa2, m)
wb = linint(mb1, wb1, mb2, wb2, m)
w = linint(va, wa, vb, wb, v)
return w
def sign(x, xsign):
"""Returns the number x with the sign of number xsign.
The function goes into trouble to ensure that the (numeric)
type of the returned value is the same with x.
if xsign is zero the sign of x is unchanged."""
if x >= 0:
if xsign >= 0: return x
else: return -x
else:
if xsign > 0: return -x
else: return x
def fsign(x, xsign):
"""Returns the float number x with the sign of number xsign."""
if xsign > 0.0: return fabs(x)
elif xsign < 0.0: return -fabs(x)
else: return float(x)
def linEq2 (a, b, c, d, e, f):
"""Solve a system of 2 linear equations.
| c b | | a c |
| f e | | d f |
ax + by = c => x = ----------- , y = -----------
dx + ey = f | a b | | a b |
| d e | | d e |
"""
delta = a*e - d*b
if delta == 0.0: return None, None
x = (c*e - f*b) / delta
y = (a*f - d*c) / delta
return (x, y)
def thanNear2(a, b):
"Checks if two 2dimensional points coincide taking numerical error into account."
xa, ya = a[:2]
xb, yb = b[:2]
d = fabs(xb-xa) + fabs(yb-ya)
v = (fabs(xa)+fabs(xb)+fabs(ya)+fabs(yb))*0.5
if v < thanThresholdx: return d < thanThresholdx
return d < v*thanThresholdx
def thanNear3(a, b):
"Checks if two 3dimensional points coincide taking numerical error into account."
xa, ya, za = a[:3]
xb, yb, zb = b[:3]
d = fabs(xb-xa) + fabs(yb-ya) + fabs(zb-za)
v = (fabs(xa)+fabs(xb)+fabs(ya)+fabs(yb)+fabs(za)+fabs(zb)) * 0.5
if v < thanThresholdx: return d < thanThresholdx
return d < v*thanThresholdx
def thanNearx(xa, xb):
"Checks if 2 coordinates (x or y) coincide taking numerical error into account."
d = fabs(xb-xa)
v = (fabs(xa)+fabs(xb))*0.5
if v < thanThresholdx: return d < thanThresholdx
return d < v*thanThresholdx
|