inddra.py :  » Business-Application » ThanCad » thancad-0.0.9 » p_gindplt » 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_gindplt » inddra.py
# -*- coding: iso-8859-7 -*-

from math import pi,cos,sin,atan2,log10,fabs
from p_gmath import dpt

MET = pi/180.0


def rnumber(dxf, x,y,h,dn,t,nn):
      "Writes the number so that its last char is at position x, y."
      if nn < 0:
          ipack = "%d" % int(dn+0.5)
      else:
          f = ".%df" % nn
          ipack = f % dn
      tt = t * pi / 180.0
      cc = cos(tt)
      ss = sin(tt)
      n=len(ipack)
      tt=n*h
      dxf.thanDxfPlotSymbol(x-tt*cc,y-tt*ss,h,ipack,t)

#==========================================================================

def cross (dxf, xx, yy, h):
      "Plots a cross."
      hh = h * 0.5
      dxf.thanDxfPlot(xx-hh, yy,    3)
      dxf.thanDxfPlot(xx+hh, yy,    2)
      dxf.thanDxfPlot(xx,    yy-hh, 3)
      dxf.thanDxfPlot(xx,    yy+hh, 2)

#===========================================================================

def elips1 (dxf, x, y, xf, yf, xc, yc, a, b, theta, idr, ic):
      """Draw an elipse approximating it with a polyline.
      implicit none
      real*8 x, y, xf, yf, xc, yc, a, b, theta             ! arguments
      integer*4 idr, ic                                    ! arguments     ! could be integer*2
      real*8 dpt                                           ! function
      external dpt
      real*8 pi, met                                       ! constants
      parameter (pi=3.14159265358979323d0, met = pi/180d0)
      integer*4 n, i     ! could be integer*2
      real*8 t, cost, sint, x1, y1, xa, ya, tha, thb, dthab, dth,
     &cosd, sind, cosx, sinx


c      y
c                                         theta =  bay ,   
c      ^                                             ab  
c      |                                           xx
c      |                     _     b
c      |                  .      \
c      |               .        / .
c      |             /        /   .
c      |           .        /     .
c      |                  o      .
c      |         .      /
c      |         .    /        /
c      |         .  /       .
c      |          \ . . .
c      |        a
c      +--------------------------------------> x
c
c
c
c      y'
c
c      ^
c      |
c      |
c      |                .   -   .
c      |            /       |       \           c  =   
c      |                    |                   ca = a
c      |       a |----------o----------| b      cb = b
c      |                    | c
c      |            \       |       /
c      |                .   _   .
c      |
c      +--------------------------------------> x'
c


c-----  sr   :
c     x, y   :      
c     xf, yf :      
c     xc, yc :        
c                
c     a, b   :     
c     theta  :          x-x
c     idr    = 0 :       
c            = 0 :       
c     ic     = 2 :         
c                     plotter      . 
c     ic     = 3 :          
c                     plotter      . 
c
c              xc,yc  a,b  theta
c            x,y  xf,yf.   
c        x,y  xf,yf    
c             .
      """
#-----  

      t = (theta - 180.0) * MET
      cost = cos(t)
      sint = sin(t)

      x1 = x - xc
      y1 = y - yc
      xa = cost * x1 + sint * y1
      ya = cost * y1 - sint * x1
      tha = atan2(ya/b, xa/a)

#-----  

      x1 = xf - xc
      y1 = yf - yc
      xa = cost * x1 + sint * y1
      ya = cost * y1 - sint * x1
      thb = atan2(ya/b, xa/a)

#-----  : default 20 ,   4 

      dthab = thb - tha
      if idr != 0: dthab = 2.0 * pi - dthab
      dthab = dpt(dthab)

      dth = 20.0 * MET
      n = int(dthab/dth)
      if n < 4: n = 4
      n = n + 1                #     =tha

      dth = dthab / n
      if idr != 0: dth = -dth
      cosd = cos(dth)
      sind = sin(dth)

#-----    t

      sint = -sint

#-----     ic

      cosx = cos(tha)
      sinx = sin(tha)

      x1 = a * cosx
      y1 = b * sinx
      xa = xc + cost * x1 + sint * y1
      ya = yc + cost * y1 - sint * x1
      dxf.thanDxfPlot (xa, ya, ic)
      dxf.thanDxfPlotPolyVertex (xa, ya, 2)

#----- 

      for i in xrange(n):
          x1 = cosx * cosd - sinx * sind
          y1 = sinx * cosd + cosx * sind
          cosx = x1
          sinx = y1

          x1 = a * cosx
          y1 = b * sinx
          xa = xc + cost * x1 + sint * y1
          ya = yc + cost * y1 - sint * x1
          dxf.thanDxfPlotPolyVertex (xa, ya, 2)
      dxf.thanDxfPlotPolyVertex (0.0, 0.0, 999)

#====================================================================

def logax (dxf, xa,ya,pw,th,emin,emax,legend,escale):
      """Plots a logarithmic axis.

c      pw: paper width in cm. if negative, legend goes to the left
c     dpw: minimum distance in cm between two numbers on the axis
c      dx: the "distance" between logs of emin and emax, in log[user units]
c     ddx: minimum distance in log[user units] between two numbers on the axis
c
      """
      HS=0.20; HSL=0.30; DPW=1.0

      dx  = log10(emax/emin)
      ddx = DPW * dx/fabs(pw)
      escale = fabs(pw)/dx

      t = th * pi/180.0
      cost = cos(t)
      sint = sin(t)

      thn = th - 90.0
      t = thn * pi/180.0
      costn = cos(t)
      sintn = sin(t)

#-----initial values

      al = log10(emax)
      k = int(al + 0.9999)
      if al < 0.0: k=k-1
      fct = 10.0 ** k

      xx = 10.0 ** (1.001 * ddx)
      anump = emin / xx
      n = 0
      an = [emax * xx]

#-----first number (anump) for new fct
      endn = False
      while True:
          anum = anump/fct
          anum = int(anum) * fct
          while True:
              anum = anum + fct
              ddxn = log10(anum/anump)
              if (ddxn < ddx): continue   # go to 20

#-------------if too big gap between anump-anum try smaller fct.

              if ddxn >= 2.0*ddx:
                  n=n+1
      if n >= len(an): an.append(anum)
      else:            an[n] = anum
                  fct = fct * 0.1
                  k = k - 1
                  break       #go to 10

#-------------if numbers for current fct finished, get new fct or end.

              while log10(an[n]/anum) < ddx:
                  if n <= 0: endn = True; break # go to 21
                  anum = an[n]
                  n = n - 1
                  fct = fct * 10.0
                  k = k + 1
                  ddxn = log10(anum/anump)

#-------------plot the number

              if anum <= emax:  # go to 31
                  dis = log10(anum/emin) * fabs(pw)/dx
#                  disn = dsign(1.5 * HS, pw)
                  disn = 1.5 * HS
      if pw < 0: disn = -disn

                  xx = xa + (dis-0.5*HS)*cost + disn*costn
                  yy = ya + (dis-0.5*HS)*sint + disn*sintn
                  k1=-k
                  if k == 0: k1=-1
                  if pw > 0.0:
                      dxf.thanDxfPlotNumber(xx, yy, HS, anum, thn, k1)
                  else:
                      rnumber(dxf, xx, yy, HS, anum, thn, k1)

#-----------------plot line

                  disn=HS
                  if pw < 0: disn = -HS
                  xx = xa + dis*cost
                  yy = ya + dis*sint
                  dxf.thanDxfPlot (xx, yy, 3)
                  dxf.thanDxfPlot (xx+disn*costn, yy+disn*sintn, 2)
              anump = anum
          if endn: break    #go to 21

#-----plot line - legend

      dxf.thanDxfPlot(xa, ya, 3)
      dxf.thanDxfPlot(xa+fabs(pw)*cost, ya+fabs(pw)*sint, 2)

      k = len(legend)
      dis = (fabs(pw) - k*HSL) * 0.5
      disn = 6.0*HS + 2.0*HSL
      if pw < 0.0: disn=-(disn-HSL)
      xx = xa + dis*cost + disn*costn
      yy = ya + dis*sint + disn*sintn
      dxf.thanDxfPlotSymbol(xx, yy, HSL, legend, th)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.