I am completely new to Fortran but have been given these files (see below) which reads an input text file, uses the Fortran code to calculate a set of values then writes them into an output text file. The programme works for all cases except Case 4, 8 and 11, producing the error:
forrtl: severe (24): end-of-file during read, unit 5, file C:\temp\sharclab\i_capa.txt
Image PC Routine Line Source
Capacity.exe 0046B6EE Unknown Unknown Unknown
Capacity.exe 00468940 Unknown Unknown Unknown
Capacity.exe 00411C9A Unknown Unknown Unknown
Capacity.exe 004118C7 Unknown Unknown Unknown
Capacity.exe 0040C416 Unknown Unknown Unknown
Capacity.exe 0040BBDA Unknown Unknown Unknown
Capacity.exe 0040714C _MAIN__ 16 main.F90
Capacity.exe 0046EB78 Unknown Unknown Unknown
Capacity.exe 004528E0 Unknown Unknown Unknown
kernel32.dll 7C817067 Unknown Unknown Unknown
I will post the code below and if anyone can help me solve this I would very much appreciate it, thank you!
First file (only the particular parts that don't function):
Case (4)
DiamRoul = abs(DonneesRlt(1))
DiamPrim = abs(DonneesRlt(2))
NbRoul = abs(int(DonneesRlt(3)))
NbRangRoul = abs(int(DonneesRlt(4)))
LongEff = abs(DonneesRlt(5))
If ((NbRoul==0).OR.(DiamPrim==0)) Then
CodeErr = 1
else ! Calcul si nb corps roulants différent de zéro
Gamma = DiamRoul / DiamPrim
FC = 17.24553 * ((1 + (1.04 * ((1 - Gamma) / (1 + Gamma))
& ** P1) ** P3) ** P4) * (((Gamma ** P2) * (1 - Gamma)
& ** P5) / ((1 + Gamma) ** P11))
ChargeDynSNR = FC * ((NbRangRoul * LongEff) ** P6)
& * (NbRoul ** P7) * (DiamRoul ** P5) * 1.1293
ChargeDynISO = FC * ((NbRangRoul * LongEff) ** P6)
& * (NbRoul ** P7) * (DiamRoul ** P5) * 1.1
ChargeStaSNR = 4.4 * (1 - Gamma) * NbRangRoul * NbRoul
& * LongEff * DiamRoul
ChargeStaISO = ChargeStaSNR
End If
Case (8)
DiamRoul = abs(DonneesRlt(1))
DiamPrim = abs(DonneesRlt(2))
NbRoul = abs(int(DonneesRlt(3)))
LongEff = abs(DonneesRlt(4))
If ((NbRoul==0).OR.(DiamPrim==0)) Then
CodeErr = 1
else ! Calcul si nb corps roulants différent de zéro
Gamma = DiamRoul / DiamPrim
FC = 34.48913 * 0.85 * (Gamma ** P2)
ChargeDynSNR = FC * (LongEff ** P6) * (NbRoul ** P7) *
& (DiamRoul ** P5) * 1
ChargeDynISO = ChargeDynSNR
ChargeStaSNR = 22 * (1 - Gamma) * NbRoul * LongEff
& * DiamRoul
ChargeStaISO = ChargeStaSNR
End If
Case (11)
DiamRoul = abs(DonneesRlt(1))
NbRoul = abs(int(DonneesRlt(2)))
LongEff = abs(DonneesRlt(3))
DiamPrim = abs(DonneesRlt(4))
AngleDeg = 45
AngleMin = 0
AngleSec = 0
NbRoul = abs(int(NbRoul / 2))
NbRangRoul = 2
DiamSpher = 0
If (NbRoul==0) Then
CodeErr = 1
else ! Calcul si nb corps roulants différent de zéro
Alpha = pi * (AngleDeg + (AngleMin / 60) + (AngleSec /
& 3600)) / 180
If (DiamPrim==0) Then
DiamPrim = (DiamSpher - DiamRoul) * DCos(Alpha)
End If
Gamma = (DiamRoul * DCos(Alpha)) / DiamPrim
FC = 17.24553 * ((1 + (1.04 * ((1 - Gamma) / (1 + Gamma))
& ** P1) ** P3) ** P4) * (((Gamma ** P2) * (1 - Gamma)
& ** P5) / ((1 + Gamma) ** P11))
ChargeDynSNR = FC * ((NbRangRoul * LongEff * DCos(Alpha))
& ** P6) * (NbRoul ** P7) * (DiamRoul ** P5) * 1.1
ChargeDynISO = ChargeDynSNR
ChargeStaSNR = 4.4 * (1 - Gamma) * NbRangRoul * NbRoul *
& LongEff * DiamRoul * DCos(Alpha)
ChargeStaISO = ChargeStaSNR
End If
End Select
! Arrondissement de toutes les charges calculées
if (ChargeDynSNR.LE.0) then
ChargeDynSNR = 0
ChargeDynSNRArr = 0
else
Call Arron(TypeRlt, ChargeDynSNR, CapaArr)
ChargeDynSNRArr = CapaArr
end if
if (ChargeDynISO.LE.0) then
ChargeDynISO = 0
ChargeDynISOArr = 0
else
Call Arron(TypeRlt, ChargeDynISO, CapaArr)
ChargeDynISOArr = CapaArr
end if
if (ChargeStaSNR.LE.0) then
ChargeStaSNR = 0
ChargeStaSNRArr = 0
else
Call Arron(TypeRlt, ChargeStaSNR, CapaArr)
ChargeStaSNRArr = CapaArr
end if
if (ChargeStaISO.LE.0) then
ChargeStaISO = 0
ChargeStaISOArr = 0
else
Call Arron(TypeRlt, ChargeStaISO, CapaArr)
ChargeStaISOArr = CapaArr
endif
! Toutes les charges calculées sont multipliées par 10.
Charges(1) = ChargeDynSNR * 10
Charges(2) = ChargeDynISO * 10
Charges(3) = ChargeStaSNR * 10
Charges(4) = ChargeStaISO * 10
ChargesArr(1) = ChargeDynSNRArr * 10
ChargesArr(2) = ChargeDynISOArr * 10
ChargesArr(3) = ChargeStaSNRArr * 10
ChargesArr(4) = ChargeStaISOArr * 10
return
END subroutine
Second file (main.F90):
program main
implicit none
integer TypeRlt
! Entrees/Sorties
real*8 DonneesRlt(15)
! Sorties
integer CodeErr
real*8 Charges(4)
integer ChargesArr(4)
open (5, FILE='C:\temp\sharclab\i_capa.txt')
open (6, FILE='C:\temp\sharclab\o_capa.txt')
read(5,*) TypeRlt
read(5,*) DonneesRlt
write(*,*) TypeRlt
write(*,*) DonneesRlt
close(5)
!TypeRlt = 5
call Capacites(TypeRlt,DonneesRlt,Charges,ChargesArr,CodeErr)
write(6,*) ChargesArr(1)
write(6,*) ChargesArr(2)
write(6,*) ChargesArr(3)
write(6,*) ChargesArr(4)
close(6)
write(*,*) ChargesArr(1)
write(*,*) ChargesArr(2)
write(*,*) ChargesArr(3)
write(*,*) ChargesArr(4)
end
I apologise if the code hasn't been copied in properly..The two text files are simply a vertical list of values for which if there isn't 15 value present (required for this Fortran programme), a value of 0 is put in it's place.
As this programme functions correctly for another cases (which I haven't posted here). I don't understand why it doesn't do the same for these cases..
There are only two calls to read, and both try to read the file i_capa.txt. When you see the error message: 'end-of-file during read' you can be pretty sure that i_capa.txt is shorter than the program expects. So my first guess is that i_capa.txt wasn't correctly set up when your program began execution.
Try changing the units from 5 and 6 to some other values: Usually unit 5 is associated with the standard input (see, e.g. http://docs.cray.com/books/S-3695-35/html-S-3695-35/pdollsmg.html)
EDIT:
How does the i_capa.txt file look like --- does it really hold two values in two lines?
Can you run the following program and see if you can read the file in:
implicit none
integer TypeRlt
real*8 DonneesRlt(15)
open (5, FILE='C:\temp\sharclab\i_capa.txt')
read(1,*) TypeRlt
read(1,*) DonneesRlt
print*, TypeRlt
print*, DonneesRlt
If this fails, would you please post the exact contents of your i_capa.txt file.
I suspect you either don't have the file, or it has less than 15 real values for DonneesRlt or it contains something else.
Related
I am looking at some Fortran code from an old scanned paper. The scan quality is not great so I may have copied it wrong. I tried to run this using an online Fortran compiler but it bombs out. Not being familiar with Fortran, I was wondering if someone can point out where the syntax does not make sense? The code is from a paper on sediment dynamics:
Komar, P.D. and Miller, M.C., 1975. On the comparison between the threshold of sediment motion under waves and unidirectional currents with a discussion of the practical evaluation of the threshold: Reply. Journal of Sedimentary Research, 45(1).
PROGRAM TSHOLD
REAL LI, LO
G = 981.0
PIE = 3.1416
RHOW = 1.00
READ (6O,1) DIAM, RHOS
1 FORMAT (2X, F6.3,2X, F5.3)
IF(DIAM .LT. 0.05) GO TO 5
A = 0.463 * PIE
B = 0.25
GO TO 7
5 A = 0.21
B = 0.50
7 PWR = 1.0 / (2.0 - B)
FAC = (A * (RHOS - RHOW) * G/(RHOW * PIE**B))**PWR
FAC1 = FAC * DIAM**((1.0 - B) * PWR)
T = 1.0
15 J = 1.20
LD = 156.13 * (T**2)
UM = FAC1 * T**(B*PWR)
WRITE(61,9) DIAM, T, UM
9 FORMAT(1H0, 10X, 17HGRAIN DIAMETER = ,F6.3,1X,2HCM //
1 11X, 14HWAVE PERIOD = ,F5.2, 1X, 3HSEC //
2 11X, 22HORBITAL VELOCITY, UM = ,F6.2, 1X, 6HCM/SECl //
3 20X, 6HHEIGHT, 5X, 5HDEPTH, 8X, 3HH/L, 6X, 7HH/DEPTH //
4 22X, 2HCM, 8X, 2HCM /)
C INCREMENT WAVE HEIGHT, CALCULATE DEPTH
H = 10.0
DO 12 K = 1.60
SING = PIE * H / (UM * T)
X = SING
IF(X.LT.1.0) GO TO 30
30 ASINH = X - 0.16666*X**3.0 + 0.07500* X ** 5.0 - 0.04464 * X ** 7.0
1 + 0.03038 * X ** 9.0 - 0.02237 * X ** 11.0
32 LI = LD * (SINH(ASINH)/COSH(ASINH))
OPTH = ASINH * LI / 6.2832
C CHECK WAVE STABILITY
RATIO = H / DPTH
IF(RATIO.GE.0.78) GO TO 11
STEEP = H / LI
TEST = 0.142 * (SINH(ASINH)/COSH(ASINH))
IF(STEEP.GE.TEST) GO TO 11
WRITE(61,10) H, OPTH, STEEP, RATIO
I0 FORMAT(IH0, 20X, F5.1, 4X, E9.3, 4X, F5.3, 4X, F4.2)
11 H = H + 10.0
12 CONTINUE
T = T + 1.0
15 CONTINUE
END
The problem is more likely that old Fortran requires fixed form code formatting where the number of spaces before a statement is very important.
Here are some general rules
Normal statements start at column 7 and beyond
Lines cannot exceed 72 columns
Any character placed on column 6 indicates the line is a continuation from the line above. I see that on the code above in the lines following 9 FORMAT(..
A number placed between columns 1-5 indicates a label, which can be a target of a GO TO statement, a DO statement or a formatting specification.
The character C on the first column, and sometimes any character on the first column indicate the line is a comment line.
see https://people.cs.vt.edu/~asandu/Courses/MTU/CS2911/fortran_notes/node4.html for more info.
Based on the rules above, here is how to enter the code, with the correct spacing. I run the F77 code through a converter to make it compatible with F90 and F77 at the same time. The code below might compile with the online compiler now.
PROGRAM TSHOLD
REAL LI, LO
G = 981.0
PIE = 3.1416
RHOW = 1.00
READ (60,1) DIAM, RHOS
1 FORMAT (2X, F6.3,2X, F5.3)
IF(DIAM .LT. 0.05) GO TO 5
A = 0.463 * PIE
B = 0.25
GO TO 7
5 A = 0.21
B = 0.50
7 PWR = 1.0 / (2.0 - B)
FAC = (A * (RHOS - RHOW) * G/(RHOW * PIE**B))**PWR
FAC1 = FAC * DIAM**((1.0 - B) * PWR)
T = 1.0
DO 15 J=1,20
LD = 156.13 * (T**2)
UM = FAC1 * T**(B*PWR)
WRITE(61,9) DIAM, T, UM
9 FORMAT(1H0, 10X, 17HGRAIN DIAMETER = ,F6.3,1X,2HCM // &
& 11X, 14HWAVE PERIOD = ,F5.2, 1X, 3HSEC // &
& 11X, 22HORBITAL VELOCITY, UM = ,F6.2, 1X, 6HCM/SECl // &
& 20X, 6HHEIGHT, 5X, 5HDEPTH, 8X, 3HH/L, 6X, 7HH/DEPTH // &
& 22X, 2HCM, 8X, 2HCM /)
! INCREMENT WAVE HEIGHT, CALCULATE DEPTH
H = 10.0
DO 12 K = 1,60
SING = PIE * H / (UM * T)
X = SING
IF(X.LT.1.0) GO TO 30
30 ASINH = X - 0.16666*X**3.0 + 0.07500* X ** 5.0 - 0.04464 * X ** 7.&
& + 0.03038 * X ** 9.0 - 0.02237 * X ** 11.0
32 LI = LD * (SINH(ASINH)/COSH(ASINH))
OPTH = ASINH * LI / 6.2832
! CHECK WAVE STABILITY
RATIO = H / DPTH
IF(RATIO.GE.0.78) GO TO 11
STEEP = H / LI
TEST = 0.142 * (SINH(ASINH)/COSH(ASINH))
IF(STEEP.GE.TEST) GO TO 11
WRITE(61,10) H, OPTH, STEEP, RATIO
10 FORMAT(G14.4, 20X, F5.1, 4X, E9.3, 4X, F5.3, 4X, F4.2)
11 H = H + 10.0
12 CONTINUE
T = T + 1.0
15 CONTINUE
END
I found several transcription errors, replacing commas with dots, zeros with the letter O, and a missing DO statement.
For some reason, both my online, and desktop compiling environments think that everything is invalid syntax all of the sudden! here is my code:
def sumn(n): #summation for sigma
return ((n + 1) * n) / 2
ipt = raw_input('How In Depth Would You Like To Go? ')
ipt = int(ipt)
pi = sumn(ipt) * ((4 / (8 * ipt + 1)) - (2 / (8 * ipt + 4)) - (1 / (8 * ipt + 5)) - (1 / (8 * ipt + 6)) * (1 / (16 ^ ipt))
print pi
Your indent for the function sumn(n)is invalid.
Your syntax for line : ipt = int(raw_input('How In Depth Would You Like To Go? ')) is incorrect.
For power use ** instead of ^.
I've got your code working with proper indentation and syntax for pi:
>>> def sumn(n): #summation for sigma
return ((n + 1) * n) / 2
>>> ipt = float(raw_input('How In Depth Would You Like To Go? '))
How In Depth Would You Like To Go? 4
>>> pi = sumn(ipt) * ((4 / (8 * ipt + 1)) - (2 / (8 * ipt + 4)) - (1 / (8 * ipt + 5)) - (1 / (8 * ipt + 6)) * (1 / (16 ** ipt)))
>>> print pi
0.386291370825
Yayy, I finally solved it!
from decimal import *
def sumn(n): #summation for sigma
return ((n + 1) * n) / 2
ipt = int(raw_input('How In Depth Would You Like To Go? '))
getcontext().prec = ipt
def factorial(n):
if n<1:
return 1
else:
return n * factorial(n-1)
def BBP(n):
pi = Decimal(0)
k = 0
while k < n:
pi += (Decimal(1) / (16 ** k)) * ((Decimal(4) / (8 * k + 1)) - (Decimal(2) / (8 * k + 4)) - (Decimal(1) / (8 * k + 5)) - (Decimal(1) / (8 * k + 6)))
k += 1
return pi
print BBP(ipt)
ex.
How In Depth Would You Like To Go? 1000
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609433057270365759591953092186117381932611793105118548074462379962749567351885752724891227938183011949129833673362440656643086021394946395224737190702179860943702770539217176293176752384674818467669405132000568127145263560827785771342757789609173637178721468440901224953430146549585371050792279689258923542019956112129021960864034418159813629774771309960518707211349999998372978049951059731732816096318595024459455346908302642522308253344685035261931188171010003137838752886587533208381420617177669147303598253490428755468731159562863882353787593751957781857780532171226806613001927876611195909216420193
The last two values are usually wrong though, and I am still working on trying to truncate them. Then all I have to do is add 2 to ipt, which would take me all of 5 seconds ☺
In implementing Blinn/Loop's algorithm on curve rendering, I realize there is a special case on Loop Curve Type. As described in their paper (subsection 4.4, page 6-7), they said the curve should be divided into two but I'm really confused how to obtain the intersection point.
Here's my rendering result:
As stated in the paper, this artifact occurs when either td/sd or te/se lie in between value [0, 1].
My source code:
...
case CURVE_TYPE_LOOP:
td = d2 + sqrt(4.0 * d1 * d3 - 3.0 * d2 *d2);
sd = 2.0 * d1;
te = d2 - sqrt(4.0 * d1 * d3 - 3.0 * d2 * d2);
se = 2.0 * d1;
if((td / sd > 0.0 && td/ sd < 1.0) || (te / se > 0.0 && te/ se < 1.0))
std::cout << "error\n";
// F matrix will be multiplied with inverse M3 to obtain tex coords (I use Eigen library btw...)
F << td * te, td * td * te, td * te * te, 1,
(-se * td) - (se * te), (-se * td * td) - (2.0 * sd * te * td), (-sd * te * te) - (2.0 * se * td * te), 0,
sd * se, te * sd * sd + 2.0 * se * td* sd, td * se * se + 2 * sd * te * se, 0,
0, -sd * sd * se, -sd * se * se, 0;
break;
...
Solved it,
I should get the splitting value t,
here's my code:
// get t
double splitLoop = -1.0;
switch (curve_type)
{
case CURVE_TYPE_UNKNOWN:
break;
case CURVE_TYPE_SERPENTINE:
tl = d2 + ((1.0 / sqrt(3.0)) * sqrt(3.0 * d2 * d2 - 4.0 * d1 * d3));
sl = 2.0 * d1;
tm = d2 - ((1.0 / sqrt(3.0)) * sqrt(3.0 * d2 * d2 - 4.0 * d1 * d3));
sm = 2.0 * d1;
F << tl * tm, tl * tl * tl, tm * tm * tm, 1,
-(sm * tl) -(sl * tm), -(3.0 * sl * tl * tl), -(3.0 * sm * tm * tm), 0,
sl * sm, 3.0 * sl * sl * tl, 3.0 * sm * sm * tm, 0,
0, -(sl * sl * sl), -(sm * sm * sm), 0;
break;
case CURVE_TYPE_LOOP:
td = d2 + sqrt(4.0 * d1 * d3 - 3.0 * d2 *d2);
sd = 2.0 * d1;
te = d2 - sqrt(4.0 * d1 * d3 - 3.0 * d2 * d2);
se = 2.0 * d1;
// Get splitting t
if((td / sd) > 0.0 && (td / sd) < 1.0)
{
splitLoop = td / sd;
}
else if((te / se) > 0.0 && (te/ se) < 1.0)
{
splitLoop = te / se;
}
F << td * te, td * td * te, td * te * te, 1,
(-se * td) - (se * te), (-se * td * td) - (2.0 * sd * te * td), (-sd * te * te) - (2.0 * se * td * te), 0,
sd * se, te * sd * sd + 2.0 * se * td* sd, td * se * se + 2 * sd * te * se, 0,
0, -sd * sd * se, -sd * se * se, 0;
break;
case CURVE_TYPE_QUADRATIC:
break;
case CURVE_TYPE_LINE:
break;
}
if(splitLoop > 0.0 && splitLoop < 1.0)
{
// SPLIT
double x01 = (x1 - x0) * splitLoop + x0;
double y01 = (y1 - y0) * splitLoop + y0;
double x12 = (x2 - x1) * splitLoop + x1;
double y12 = (y2 - y1) * splitLoop + y1;
double x23 = (x3 - x2) * splitLoop + x2;
double y23 = (y3 - y2) * splitLoop + y2;
double x012 = (x12 - x01) * splitLoop + x01;
double y012 = (y12 - y01) * splitLoop + y01;
double x123 = (x23 - x12) * splitLoop + x12;
double y123 = (y23 - y12) * splitLoop + y12;
double x0123 = (x123 - x012) * splitLoop + x012;
double y0123 = (y123 - y012) * splitLoop + y012;
// CURVE A (recursive)
DrawCubic(x0, y0, x01, y01, x012, y012, x0123, y0123);
// CURVE B (recursive)
DrawCubic(x0123, y0123, x123, y123, x23, y23, x3, y3);
}
else
{
// Draw as usual...
}
== EDIT ==
After i experimented again for a while, There's a numerical error on my program when the values of td/sd or te/se on subcurves lie again in between [0, 1], since my program use recursive by calling DrawCubic(), it causes recursive heap error.
In the meantime, I use 'hack' solution where I will not call DrawCurve() inside the recursive call (making sure the recursive is called only once). So far the result is quite satisfying and I don't see any artifact.
Any feedback is really welcomed since I'm not really good in numerical calculation :)
The original second order ODEs are
x'' - 2 * omega * y' - omega ** 2 * x = - mue * (x + pi2 * r12) / np.sqrt((x + pi2 * r12) ** 2 + y ** 2) ** 3 - mum * (x - pi1 * r12) / np.sqrt((x - pi1 * r12) ** 2 + y ** 2)
y'' + 2 * omega * x' - omega **2 * y = - mue * y / np.sqrt((x + pi2 * r12) ** 2 + y ** 2) ** 3 - mum * y / np.sqrt((x - pi1 * r12) ** 2 + y ** 2)
z'' = 0
So here is the code I used to solve the ODE but first I broke it up into 2 first orders.
I am receiving the error that the module on line 61 is not callable.
Line 61 is u = odeint(deriv, u0, dt)
#!/usr/bin/env python
import numpy as np
import scipy.integrate as odeint
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
me = 5.974 * 10 ** (24) # mass of the earth
mm = 7.348 * 10 ** (22) # mass of the moon
G = 6.67259 * 10 ** (-20) # gravitational parameter
re = 6378.0 # radius of the earth in km
rm = 1737.0 # radius of the moon in km
r12 = 384400.0 # distance between the CoM of the earth and moon
M = me + mm
pi1 = me / M
pi2 = mm / M
mue = 398600.0 # gravitational parameter of earth km^3/sec^2
mum = G * mm # grav param of the moon
mu = mue + mum
omega = np.sqrt(mu / r12 ** 3)
nu = 0.0 # flight path angle
x = 327156.0 # x location where the moon's SOI effects the spacecraft
y = 33050.0 # y location
vbo = 10.85 # velocity at burnout
gamma = -141.868 * np.pi / 180 # angle in radians of true anomaly
vx = vbo * (np.sin(gamma) * np.cos(nu) - np.cos(gamma) * np.sin(nu))
# velocity of the bo in the x direction
vy = vbo * (np.sin(gamma) * np.sin(nu) + np.cos(gamma) * np.cos(nu))
# velocity of the bo in the y direction
xrel = (re + 300.0) * np.cos(gamma)
# spacecraft x location relative to the earth
yrel = (re + 300.0) * np.sin(gamma)
# r0 = [xrel, yrel, 0]
# v0 = [vx, vy, 0]
u0 = [xrel, yrel, 0, vx, vy, 0]
def deriv(u, dt):
n1 = -((mue * (u[0] + pi2 * r12) / np.sqrt((u[0] + pi2 * r12) ** 2
+ u[1] ** 2) ** 3)
- (mum * (u[0] - pi1 * r12) / np.sqrt((u[0] - pi1 * r12) ** 2
+ u[1] ** 2) ** 3))
n2 = -((mue * u[1] / np.sqrt((u[0] + pi2 * r12) ** 2 + u[1] ** 2) ** 3)
- (mum * u[1] / np.sqrt((u[0] - pi1 * r12) ** 2 + u[1] ** 2) ** 3))
return [u[3], # dotu[0] = u[3]
u[4], # dotu[1] = u[4]
u[5], # dotu[2] = u[5]
2 * omega * u[5] + omega ** 2 * u[0] + n1, # dotu[3] = that
omega ** 2 * u[1] - 2 * omega * u[4] + n2, # dotu[4] = that
0] # dotu[5] = 0
dt = np.arange(0.0, 250000.0, .1)
u = odeint(deriv, u0, dt)
x, y, z, x2, y2, z2 = u.T
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, z)
plt.show()
Assuming you mean this error:
~/coding$ python orbit1.py
Traceback (most recent call last):
File "orbit1.py", line 61, in <module>
u = odeint(deriv, u0, dt)
TypeError: 'module' object is not callable
This is because you want the function named odeint in scipy.integrate. Your line
import scipy.integrate as odeint
imports the entire module and gives it the name odeint. Try
from scipy.integrate import odeint
instead, or
import scipy.integrate
[...]
u = scipy.integrate.odeint(deriv, u0, dt)
which should give you
I'm making a vector drawing application and noticed that Anti Grain Geometry have an example that does exactly what I want. http://www.antigrain.com/demo/index.html then below there is an example on perspective for Win32. I don't understand their cpp file. Based on this example. If I have a bunch of verticies to form an object, like their lion, and then I have 4 verticies as control points, how could I achieve their effect? Ex, what transformation do I apply to each point?
Thanks
From that very page you posted, there's a link to the source
code. I'll explain the bilinear transformation in
http://www.antigrain.com/__code/include/agg_trans_bilinear.h.html
The idea here is to find a transformation of the form:
output_x = a * input_x + b * input_x * input_y + c * input_y + d
output_y = e * input_x + f * input_x * input_y + g * input_y + h
The term "bilinear" comes from each of those equations being linear in
either of the input coordinates by themselves. We want to solve for
the right values of a, b, c, and d. Say you have the reference
rectangle r1, r2, r3, r4 which you want to map to (0,0), (1,0), (0,1),
(1,1) (or some image coordinate system).
For a,b,c,d:
0 = a * r1_x + b * r1_x * r1_y + c * r1_y + d
1 = a * r2_x + b * r2_x * r2_y + c * r2_y + d
0 = a * r3_x + b * r3_x * r3_y + c * r3_y + d
1 = a * r4_x + b * r4_x * r4_y + c * r4_y + d
For e,f,g,h:
0 = e * r1_x + f * r1_x * r1_y + g * r1_y + h
0 = e * r2_x + f * r2_x * r2_y + g * r2_y + h
1 = e * r3_x + f * r3_x * r3_y + g * r3_y + h
1 = e * r4_x + f * r4_x * r4_y + g * r4_y + h
You can solve this however you like best. (If you're familiar with
matrix notation, these are two matrix equations for which the matrix
is the same, and then you simply need to find the LU decomposition
once, and solve the two unknown vectors). The coefficients are then
applied to map the interior of the rectangle to the position in the
rectangle.
If by any chance you're looking for the inverse transform, that is,
if you want to know where a given pixel will land, you simply switch
inputs and outputs:
For a,b,c,d:
r1_x = a * 0 + b * 0 * 0 + c * 0 + d
r2_x = a * 1 + b * 1 * 0 + c * 0 + d
r3_x = a * 0 + b * 0 * 1 + c * 1 + d
r4_x = a * 1 + b * 1 * 1 + c * 1 + d
For e,f,g,h:
r1_y = e * 0 + f * 0 * 0 + g * 0 + h
r2_y = e * 1 + f * 1 * 0 + g * 0 + h
r3_y = e * 0 + f * 0 * 1 + g * 1 + h
r4_y = e * 0 + f * 0 * 1 + g * 1 + h
You're talking about perspective transformation from 2D planar onto a square 'in space' I think.
Well - This one is not that difficult. The mathematics are explained in the paper:
Heckbert, Paul, Fundamentals of
Texture Mapping and Image Warping,
Master’s thesis, UCB/CSD 89/516, CS
Division, U.C. Berkeley, June 1989.
(I don't link to the paper due to copyright reasons. It's available on the net and you shouldn't have any problems finding it though)
This gives you the math and some ready to use equations to do it.
If you are looking for some "easy to rip" code I suggest to download the OpenVG reference implementation and take a close look at the functions "vguComputeWarpQuadToSquare", "vguComputeWarpSquareToQuad" and "vguComputeWarpQuadToQuad" :-) They cover all you need.
Download here: http://www.khronos.org/registry/vg/ri/openvg-1.1-ri.zip
These functions will calculate a 3x3 matrix that does the transformation. To use this matrix you have to extend your 2D coordinates into 2D homogenous coordinates. That's not that difficult but beyond the scope of the question. If you need help to work with them I suggest that you ask that in a different question.