01.3차원 물체와 벡터 표현 - gobuksun/mywiki GitHub Wiki
GlowScript 2.9 VPython
#Creating Ball
myBall = sphere(color=color.red, radius=2)
#Creating Box
myBox = box(pos = vec(5,0,0), color = color.blue, size = vec(0.5,4,1))
myBall.color = color.green
myBox.pos.x = 10
-
A vector has magnitude (size)크기 and direction방향
The length of the line shows its magnitude and the arrowhead points in the direction.
We can add two vectors by joining them head-to-tail
-
We can also subtract one vector from another
-
Notation
The vector a is broken up into the two vectors ax and ay
Example: add the vectors a = (8, 13) and b = (26, 7)
c = a + b
c = (8, 13) + (26, 7) = (8+26, 13+7) = (34, 20)
Example: subtract k = (4, 5) from v = (12, 2)
a = v + −k
a = (12, 2) + −(4, 5) = (12, 2) + (−4, −5) = (12−4, 2−5) = (8, −3)
- Magnitude of a Vector
The magnitude of a vector is shown by two vertical bars on either side of the vector:
|a|
OR it can be written with double vertical bars (so as not to confuse it with absolute value):
||a||
We use Pythagoras' theorem to calculate it:
|a| = √( x2 + y2 )
Example: what is the magnitude of the vector b = (6, 8) ?
|b| = √( 62 + 82) = √( 36+64) = √100 = 10
A vector with magnitude 1 is called a Unit Vector.
- Unit Vector
A Unit Vector has a magnitude of 1:
The symbol is usually a lowercase
letter with a "hat", such as:
(Pronounced "a-hat")
Scaling
A vector can be "scaled" off the unit vector. Here vector a is shown to be 2.5 times a unit vector. Notice they still point in the same direction:
- Velocity속도, acceleration가속도, force힘 and many other things are vectors.
GlowScript 2.9 VPython
#Vectors
r= vector(3,4,5)
r_arrow = arrow(pos = vector(0,0,0), axis=r, shafrwidth=0.2)
#Axes
(사물의) (중심) 축, 축선x_axis = arrow(axis=vector(10,0,0), color=color.red, shaftwidth=0.1)
y_axis = arrow(axis=vector(0,10,0), color=color.green, shaftwidth=0.1)
z_axis = arrow(axis=vector(0,0,10), color=color.blue, shaftwidth=0.1)
r_mag = mag(r) // 벡터의 크기 : 스칼라값
r_hat = norm(r) // 벡터의 방향 : 단위벡터
r_hat_arrow = arrow(axis=r_hat, color=color.cyan, shaftwidth=0.2)
print("r:", r)
print("r_mag:", r_mag)
print("r_hat:", r_hat)
GlowScript 3.0 VPython
a = vector(3,4,0)
b = vector(5,1,0)
# 벡터더하기
c = a + b
# 벡터빼기
d = a - b
# 벡터의내적
e = dot(a,b)
deg = acos(e/mag(a)/mag(b)) ## rad
deg = degrees(deg) ## deg
a_arrow = arrow(pos=vector(0,0,0), axis=a, shaftwidth=0.2,color=color.blue)
b_arrow = arrow(pos=vector(0,0,0), axis=b, shaftwidth=0.2,color=color.green)
#c_arrow = arrow(pos=vector(0,0,0), axis=c, shaftwidth=0.2,color=color.red)
d_arrow = arrow(pos=b, axis=d, shaftwidth=0.2,color=color.red)
print("dot(a,b) =", e)
print("degree(a,b) =", deg)
print("a+b=", c)
print("a-b=", d)
벡터의 내적 : 벡터로 이루어진 물리량을 분해할때 많이 쓰임, 힘을 분해한다든지, 속도를 분해한다든지...
How do we multiply two vectors together? There is more than one way!
(Read those pages for more details.) |
GlowScript 2.9 VPython
#Vectors
a = vector(1,2,3)
b = vector(-1,2,0)
c = cross(a,b)
a_arr = arrow(axis=a, shaftwidth=0.1, color=color.red)
b_arr = arrow(axis=b, shaftwidth=0.1, color=color.blue)
c_arr = arrow(axis=c, shaftwidth=0.1)
d = cross(b,a)
d_arr = arrow(axis=d, shaftwidth=0.1, color=color.yellow)
GlowScript 2.9 VPython
#Vectors
v = vector(3,4,0)
r = vector(1,0,0)
v_par = dot(v,r)*r
v_per = v - v_par
v_arr = arrow(axis=v, shaftwidth=0.2)
r_arr = arrow(axis=r, shaftwidth=-0.3, color=color.blue)
v_par_arr = arrow(axis=v_par, shaftwidth=0.2, color= color.green)
v_per_arr = arrow(axis=v_per, shaftwidth=0.2, color= color.yellow)
print("v=", v)
print("r=", r)
print("dot(v,r)=", dot(v,r))
print("v_par=", v_par)
print("v_per=", v_per)