如何讓你的 fortran 程式,叫AutoCAD 自動畫圖

92 views
Skip to first unread message

sjgau02

unread,
Oct 18, 2007, 4:52:05 PM10/18/07
to NTUST_F90
所謂的一張圖,勝過千言萬語。
這個技術,非常的實用,卻很少人會。

簡單的不得了。
以下,以範例解釋:

假設,你的fortran 程式產生一條 curve, sin- curve
0 - 360 的 sin-curve

只要你的 fortran 程式,輸出資料檔案格式如下

pline
x1,y1
x2,y2
.
.
.
xn,yn

pline
x1,y1
x2,y2
.
.
.
xn,yn

以上,是兩條 curve, 中間用一個 空行隔開。

如此,就可以讓 AutoCAD 讀這個檔案,自動產生圖形。
帥吧!

就是 這麼簡單。

下次的meeting, 我會 展示這個範例,
同時,提供這個範例 完整的 電子檔案給大家,
讓大家可以 自己釣魚。

ps. 請周同學 務必通知每一個同學 盡快到這個討論區 報到,
謝謝!

sjgau02

unread,
Oct 18, 2007, 5:13:29 PM10/18/07
to NTUST_F90
以下為產生 sun- curve 的fortran 程式
有不了解的地方,請踴躍提出問題。


implicit none
real dtor

real x1,x2,dx, x,y
integer no

! for x=0 to 360 step dx do ...
x1= 0.0
x2= 360.0
no= 64

dx= (x2 - x1)/no
x2= x2 + dx/10.0
open(unit= 10, file= 'test1.txt', status= 'REPLACE')

x= x1
do while (x .LE. x2)
y= sin(dtor(x))
write(10, '(1x, 2F10.4)')x, y

x= x + dx
end do

close(unit= 10)
end
! -------------------------------------------

function dtor(d1)
implicit none
real dtor, d1

dtor= d1/180.0*(4.0*atan(1.0))

end

sjgau02

unread,
Oct 18, 2007, 5:16:32 PM10/18/07
to NTUST_F90
為了簡化這個範例,我們修改檔案格式如下:

一: 一次只能畫 一條 curve

二 :不用加 pline 這一行

所以,輸出的檔案格式如下

sjgau02

unread,
Oct 19, 2007, 9:16:33 AM10/19/07
to NTUST_F90
叫AutoCAD自動畫圖的心得分享(附VC源碼)

假設,你的應用程式產生如下的數據檔案
它所代表的是一條曲線。
以下的方法可以讓你很容易的叫AutoCAD
自動產生這條曲線。
事實上,這個方法可以適用於所有AutoCAD
所提供的畫圖元件,而且2D/3D都適合使用。

0.000000 0.000000
0.196350 0.195090
0.392699 0.382683
0.589049 0.555570
0.785398 0.707107
0.981748 0.831470
1.178097 0.923880
1.374447 0.980785
1.570796 1.000000
1.767146 0.980785
1.963495 0.923880
2.159845 0.831470
2.356194 0.707107
2.552544 0.555570
2.748894 0.382683
2.945243 0.195090
3.141593 0.000000
3.337942 -0.195090
3.534292 -0.382683
3.730641 -0.555570
3.926991 -0.707107
4.123340 -0.831470
4.319690 -0.923880
4.516039 -0.980785
4.712389 -1.000000
4.908739 -0.980785
5.105088 -0.923880
5.301438 -0.831470
5.497787 -0.707107
5.694137 -0.555570
5.890486 -0.382683
6.086836 -0.195090
6.283185 -0.000000

產生以上數據的程式源碼
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <process.h>
// ----------------------------------------------

// x= dtor( t);
double dtor(double d1)
{
return(d1/180.0*(4.0*atan(1.0)));
}// end of dtor()
// ----------------------------------------------


void main(int argc, char *argv[])

{
// generate sin-curve data
// for theta= 0 to 360 step dt do ...

int no;
double t1, t2, dt, t, x, y;
FILE *f1;
// ----------------------------------------------

if ((f1= fopen(argv[1], "wt")) == NULL) {
printf("*** error of fopen() == NULL\n");
_getch();

exit(1);
}
// ----------------------------------------------

t1= 0.0;
t2= 360.0;
no= 32;
dt= (t2 - t1)/no;
for (t= t1;t <= (t2 + 0.1*dt);t+= dt) {
x= dtor(t);
y= sin(x);

// plot x, y
fprintf(f1, "%10.6lf %10.6lf\n", x, y);
}

fclose(f1);
}// end of main()

為了避免被公幹,需要的人請前往我的部落格 留言索取

http://myblog.pchome.com.tw/sjgau/


Reply all
Reply to author
Forward
0 new messages