clear;clf;cla reset; % 초기화 X=[0 1 1 0]; % 개미 각각의 초기 X 좌표 Y=[0 0 1 1]; % Y 좌표 Z=[0 1 0 1]; % Z 좌표 r=[X;Y;Z]; % 개미들의 위치 v=0.01; % 속도 track=r; % 개미의 위치 변화 tmax=400; % 최대 시간 color=char('or','hb','+','d'); % 표시 형식
hold on for t=2:tmax direction=r(:,[2 3 4 1])-r(:,[1 2 3 4]); % 방향 벡터 udir=direction/norm(direction(:,1)); % 단위 벡터 r=r+v*udir; % 위치 계산 if norm(r(:,1)-[0.5;0.5;0.5]) < 0.01 % 중앙 위치에 가까워지면 종료. break; end track(:,:,t)=r; % 좌표를 track에 저장 end
for m=1:4 %SQUEEZE Remove singleton dimensions x(:,m)=squeeze(track(1,m,:));y(:,m)=squeeze(track(2,m,:));z(:,m)=squeeze(track(3,m,:)); end
plot3(x,y,z) % 입체로 그래프 그림
for m=1:4 % 개미를 좌표에 표시 p(m)=plot3(x(1,m),y(1,m),z(1,m),color(m)); end
view(3) % 입체로 보기 grid on; % 눈금선 표시
for t=1:length(x(:,1)) % 개미의 이동을 애니메이션 처럼 표시 for m=1:4 set(p(m),'XData',x(t,m),'YData',y(t,m),'ZData',z(t,m)) end drawnow end hold off
X=[0 0 1 1]; % X 좌표 Y=[0 1 1 0]; % Y 좌표 r=[X;Y]; v=0.0005; % 개미의 이동 속도 track=r; % 초기 위치 좌표 tmax=10000; % 최종 시간 color=char('or','hb','+','d'); % 4마리 개미 표시 설정
for t=2:tmax direction=r(:,[2 3 4 1])-r(:,[1 2 3 4]); % 앞의 개미에서 자신의 위치를 계산한 방향 udir=direction/norm(direction(:,1)); % 방향 단위 벡터 r=r+v*udir; % 속도에 방향을 곱하여 위치 계산 if norm(r(:,1)-[0.5;0.5]) < 0.01 % 개미가 중앙에 오면 break 명령 break; end track(:,:,t)=r; % 개미 4마리의 위치를 track에 저장 end
t=1; % 값 초기화 x=[];y=[]; for m=1:4 % 각 개미의 x,y 좌표를 track으로 부터 계산 x(:,m)=squeeze(track(1,m,:)); y(:,m)=squeeze(track(2,m,:)); end
clf % 기존 이미지를 지우고 재설정 cla reset; hold on % 이미지 유지 on plot(x,y) % 개미의 궤적을 그림 for m=1:4 % 개미 4마리를 초기 위치에 표시 p(m)=plot(x(1,m),y(1,m),color(m),'EraseMode','xor'); end
for t=1:length(x(:,1)) % 시간의 변화에 따라 set을 이용하여 개미 위치 변화 for m=1:4 set(p(m),'XData',x(t,m),'YData',y(t,m)) end drawnow end
In mathematics, the spherical coordinate system is a coordinate system for representing geometric figures in three dimensions using three coordinates: the radial distance of a point from a fixed origin, the zenith angle from the positive z-axis, and the azimuth angle from the positive x-axis.
Definition The three coordinates (ρ, θ, φ) are defined as:
* ρ ≥ 0 is the distance from the origin to a given point P. * 0 ≤ θ ≤ 360° is the angle between the positive x-axis and the line from the origin to the P projected onto the xy-plane. * 0 ≤ φ ≤ 180° is the angle between the positive z-axis and the line formed between the origin and P.
θ is referred to as the azimuth, while φ is referred to as the zenith, colatitude or polar angle. θ and φ and lose significance when ρ = 0 and θ loses significance when sin(φ) = 0 (at φ = 0 and φ = 180°).
To plot a point from its spherical coordinates, go ρ units from the origin along the positive z-axis, rotate φ about the y-axis in the direction of the positive x-axis and rotate θ about the z-axis in the direction of the positive y-axis.
Coordinate system conversions As the spherical coordinate system is only one of many three-dimensional coordinate systems, there exist equations for converting coordinates between the spherical coordinate system and others.
Cartesian coordinate system The three spherical coordinates are obtained from Cartesian coordinates by: Note that the arctangent must be defined suitably so as to take account of the correct quadrant of y / x. The atan2 or equivalent function accomplishes this for computational purposes.
Conversely, Cartesian coordinates may be retrieved from spherical coordinates by:
Cylindrical coordinate system
The cylindrical coordinate system is a three-dimensional extrusion of the polar coordinate system, with an h coordinate to describe a point's height above or below the xy-plane. The full coordinate tuple is (r, θ, h).
Cylindrical coordinates may be converted into spherical coordinates by:
Spherical coordinates may be converted into cylindrical coordinates by:
수학에서 외적(外積)은 3차원 공간의 벡터들간의 이항연산의 일종이다. 연산의 결과가 스칼라인 내적(內積)과는 달리 연산의 결과가 벡터이기 때문에 벡터곱(vector product)이라고 불리기도 한다. 외적은 물리학의 각운동량, 로렌츠 힘등의 공식에 등장한다.
정의
두 벡터 a와 b의 외적은 a x b라 쓰고(수학자들은 a ^ b라고 쓰기도 한다.), 다음과 같이 정의된다.
식에서 θ는 a와 b가 이루는 각을 나타내며, n은 a와 b에 공통으로 수직인 단위벡터를 나타낸다.
위 정의에서의 문제점은 a와 b에 공통으로 수직인 방향이 두개라는 점이다. 즉, n이 수직이면, -n도 수직이다.
어느 것을 두 벡터의 외적으로 할 것인가는 벡터공간의 방향성(orientation)에 따라 달라진다. 오른손 좌표계에서는 a×b는, a, b, a×b가 오른손 좌표계 방향을 따르도록 정의되고, 왼손좌표계에선 마찬가지로 이 순서의 세 벡터가 왼손 좌표계 방향을 따르도록 정의된다.
In mathematics, the cross product is a binary operation on two vectors in a three-dimensional Euclidean space that results in another vector which is perpendicular to the two input vectors. By contrast, the dot product produces a scalar result. In many engineering and physics problems, it is handy to be able to construct a perpendicular vector from two existing vectors, and the cross product provides a means for doing so. The cross product is also known as the vector product, or Gibbs vector product.
The cross product is not defined except in three-dimensions (and the algebra defined by the cross product is not associative). Like the dot product, it depends on the metric of Euclidean space. Unlike the dot product, it also depends on the choice of orientation or "handedness." Certain features of the cross product can be generalized to other situations. For arbitrary choices of orientation, the cross product must be regarded not as a vector, but as a pseudovector. For arbitrary choices of metric, and in arbitrary dimensions, the cross product can be generalized by the exterior product of vectors, defining a two-form instead of a vector.
Definition
The cross product of two vectors a and b is denoted by a × b. In a three-dimensional Euclidean space, with a usual right-handed coordinate system, it is defined as a vector c that is perpendicular to both a and b, with a direction given by the right-hand rule and a magnitude equal to the area of the parallelogram that the vectors span.
The cross product is given by the formula
where θ is the measure of the (non-obtuse) angle between a and b (0° ≤ θ ≤ 180°), a and b are the magnitudes of vectors a and b, and is a unit vector perpendicular to the plane containing a and b. If the vectors a and b are collinear (i.e., the angle θ between them is either 0° or 180°), by the above formula, the cross product of a and b is the zero vector 0.
The direction of the vector is given by the right-hand rule, where one simply points the forefinger of the right hand in the direction of a and the middle finger in the direction of b. Then, the vector is coming out of the thumb (see the picture on the right).
Using the cross product requires the handedness of the coordinate system to be taken into account (as explicit in the definition above). If a left-handed coordinate system is used, the direction of the vector is given by the left-hand rule and points in the opposite direction.
This, however, creates a problem because transforming from one arbitrary reference system to another (e.g., a mirror image transformation from a right-handed to a left-handed coordinate system), should not change the direction of . The problem is clarified by realizing that the cross-product of two vectors is not a (true) vector, but rather a pseudovector. See cross product and handedness for more detail.
The dot product of two vectors (from an orthonormal vector space) a = [a1, a2, … , an] and b = [b1, b2, … , bn] is by definition:
where Σ denotes summation notation.
For example, the dot product of two three-dimensional vectors [1, 3, −5] and [4, −2, −1] is
Using matrix multiplication and treating the (column) vectors as n×1 matrices, the dot product can also be written as:
where aT denotes the transpose of the matrix a.
Using the example from above, this would result in a 1×3 matrix (i.e., vector) multiplied by a 3×1 vector (which, by virtue of the matrix multiplication, results in a 1×1 matrix, i.e., a scalar):
-------------------------------------------------------------------------------------------------- The dot product of two vectors a and b (sometimes called inner product, or, since its result is a scalar, the scalar product) is denoted by a ∙ b and is defined as:
where ||a|| and ||b|| denote the norm (or length) of a and b, and θ is the measure of the angle between a and b (see trigonometric function for an explanation of cosine). Geometrically, this means that a and b are drawn with a common start point and then the length of a is multiplied with the length of that component of b that points in the same direction as a.
The dot product can also be defined as the sum of the products of the components of each vector:
where a and b are vectors of n dimensions; a1, a2, …, an are coordinates of a; and b1, b2, …, bn are coordinates of b.
This operation is often useful in physics; for instance, work is the dot product of force and displacement.