曲線、速度ベクトル、加速度ベクトル
例題1
曲線を描かせる
*******************************
!curve01.bas 02-7-14
!曲線を描かせる。
let s=50
set window -0.5*s,0.8*s,-0.3*s,s
let dt=0.001
let a=10
!------------------関数を定義する。
def xx(t)=a*cos(t)
def yy(t)=a*sin(t)
def zz(t)=t
! 曲線-------------------------------------
set line width 5
set line color 2
for i=0 to 30000
call plotto(xx(t),yy(t),zz(t))
let t=t+dt
next i
!*******************************
plot lines
set line width 1
set line color 1
! 軸------------------------------------------------
call plotto(0,0,0)
call plotto(40,0,0)
call plotto(0,0,0)
call plotto(0,40,0)
call plotto(0,0,0)
call plotto(0,0,40)
call penup
call plottext(40,0,0,"x")
call plottext(0,40,0,"y")
call plottext(0,0,40,"z")
call plottext(-2,-1,-2,"0")
!---subroutines-------------------------------------------
sub rotx(x,y,z,a)
let y0=y*cos(a)-z*sin(a)
let z0=y*sin(a)+z*cos(a)
let y=y0
let z=z0
end sub
sub roty(x,y,z,a)
let x0=x*cos(a)+z*sin(a)
let z0=-x*sin(a)+z*cos(a)
let x=x0
let z=z0
end sub
sub rotz(x,y,z,a)
let x0=x*cos(a)-y*sin(a)
let y0=x*sin(a)+y*cos(a)
let x=x0
let y=y0
end sub
sub convert(x,y,z)
call rotz(x,y,z,-30*pi/180)
call rotx(x,y,z,-70*pi/180)
end sub
sub plotto(x,y,z)
let x1=x
let y1=y
let z1=z
call convert(x1,y1,z1)
plot lines:x1,y1;
end sub
sub penup
plot lines
end sub
sub plottext(x,y,z,s$)
call convert(x,y,z)
plot text ,at x,y: s$
end sub
END
***********************************************
例題2
曲線の速度ベクトルと加速度ベクトルを求める。
*************************************************
!curve02.bas 02-7-14 rev. 03-01-16
!曲線の速度ベクトルと加速度ベクトルを求める。
let s=50
set window -0.5*s,0.8*s,-0.3*s,s
let dt=0.01
let a=10
!----------------------関数の定義
def xx(t)=a*cos(t)
def yy(t)=a*sin(t)
def zz(t)=t
!----------------------速度の定義
def vx(t)=(xx(t+dt)-xx(t))/dt
def vy(t)=(yy(t+dt)-yy(t))/dt
def vz(t)=(zz(t+dt)-zz(t))/dt
!----------------------加速度の定義
def ax(t)=(vx(t+dt)-vx(t))/dt
def ay(t)=(vy(t+dt)-vy(t))/dt
def az(t)=(vz(t+dt)-vz(t))/dt
! 曲線-----------------------------------------
set line width 2
set line color 2
for i=0 to 2400
call plotto(xx(t),yy(t),zz(t))
let t=t+dt
next i
!--------速度ベクトル---------
let x=xx(t)
let y=yy(t)
let z=zz(t)
let kx=vx(t)
let ky=vy(t)
let kz=vz(t)
print "t=";t
print "x y z =";x;y;z
print "velocity vector=";kx;ky;kz
print "velocity=";sqr(kx^2+ky^2+kz^2)
set line width 2
set line color 4
call drawvectorarrow
!--------加速度ベクトル---------
let x=xx(t)
let y=yy(t)
let z=zz(t)
let kx=ax(t)
let ky=ay(t)
let kz=az(t)
print "acceleration vector=";kx;ky;kz
print "acceleration=";sqr(kx^2+ky^2+kz^2)
set line width 2
set line color 3
call drawvectorarrow
!*************************************
sub drawvectorarrow
call convert(x,y,z)
call convert(kx,ky,kz)
plot points :x,y
let leng=sqr(kx^2+ky^2+kz^2)
if kx<>0 then
let theta=angle(kx,ky)
let x1=x
let y1=y
draw arrow with rotate(theta)*scale(leng)*shift(x1,y1)
end if
end sub
plot lines
set line width 1
set line color 1
! 軸------------------------------------------------
call plotto(0,0,0)
call plotto(40,0,0)
call plotto(0,0,0)
call plotto(0,40,0)
call plotto(0,0,0)
call plotto(0,0,40)
call penup
call plottext(40,0,0,"x")
call plottext(0,40,0,"y")
call plottext(0,0,40,"z")
call plottext(-2,-1,-2,"0")
!----subroutines-------------------------------------------
sub rotx(x,y,z,a)
let y0=y*cos(a)-z*sin(a)
let z0=y*sin(a)+z*cos(a)
let y=y0
let z=z0
end sub
sub roty(x,y,z,a)
let x0=x*cos(a)+z*sin(a)
let z0=-x*sin(a)+z*cos(a)
let x=x0
let z=z0
end sub
sub rotz(x,y,z,a)
let x0=x*cos(a)-y*sin(a)
let y0=x*sin(a)+y*cos(a)
let x=x0
let y=y0
end sub
sub convert(x,y,z)
call rotz(x,y,z,-30*pi/180)
call rotx(x,y,z,-70*pi/180)
end sub
sub plotto(x,y,z)
let x1=x
let y1=y
let z1=z
call convert(x1,y1,z1)
plot lines:x1,y1;
end sub
sub penup
plot lines
end sub
sub plottext(x,y,z,s$)
call convert(x,y,z)
plot text ,at x,y: s$
end sub
END
!------------
external picture arrow
let aa=30/180*pi
plot 0,0;1,0
plot 1,0;1-0.2*cos(aa),-0.2*sin(aa)
plot 1,0;1-0.2*cos(aa),0.2*sin(aa)
end picture