var.py :  » Business-Application » ThanCad » thancad-0.0.9 » p_gmath » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » ThanCad 
ThanCad » thancad 0.0.9 » p_gmath » var.py
# -*- 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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.