[100] 013 Tutorial vertex - msharpmath, The Simple is the Best

advertisement
[100] 013
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
revised on 2012.10.28
cemmath
The Simple is the Best
Chapter 13 Vertex and Coordinate System
13-1
13-2
13-3
13-4
13-5
13-6
Class ‘vertex’
Operations for Vertices
Member Functions for Vertices
Class ‘csys’
Application Examples
Summary
The class ‘vertex’ is very useful in handling geometry in the threedimensional space. For example, mesh generation can be carried out by using
vertex arrays. This leads to an introduction of another important data type
‘csys’ which represents a coordinate system. In this chapter, we discuss data
types of ‘vertex’ and ‘csys’.
Section 13-1 Class ‘vertex’
β–  Data Structure of Vertex. The vertex in two-dimension or in threedimension is defined as
𝐯 = 𝐒π‘₯ + 𝐣𝑦, 𝐯 = 𝐒π‘₯ + 𝐣𝑦 + 𝐀𝑧
where 𝐒, 𝐣, 𝐀 are the unit vectors in the Cartesian coordinates, and 𝑧 = 0 is
assumed in two-dimensional space. In Cemmath, the vertex is denoted by
v = < x, y >
v = < x, y, z >
where π‘₯, 𝑦, 𝑧 are double data. In Cemmath, all the vertex data are stored as the
1
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
three-dimensional data. The default format for displaying vertices is
“< %12.4g
%12.4g
%12.4g >”
which can be changed by
vertex.format(“string”)
This can be confirmed by the following Cemmath commands
%>
#>
#>
#>
#>
default display
x = 1;;
y = pi;; z = sqrt(2);;
v = <x,y,z>;
vertex.format(" %15.6e, %15.6e, %15.6e");
vertex.format("< %12.4g %12.4g %12.4g >");
v = <
1
v =
1.000000e+000,
v = <
1
v;
v;
3.142
1.414 >
3.141593e+000,
1.414214e+000
3.142
1.414 >
β–  Writing Coordinate System. The principal coordinate systems are the
Cartesian (rectangular), cylindrical and spherical coordinate systems. The polar
coordinate system is considered to be the cylindrical coordinate system with
𝑧 = 0 . The global Cartesian coordinate is the default coordinate and is
designated
<x,y,z, rec>
which is the same as
<x,y,z>
// the default writing system is always Cartesian
The polar coordinate (π‘Ÿ, πœƒ) or the cylindrical coordinate (π‘Ÿ, πœƒ, 𝑧) defined as
π‘₯ = π‘Ÿ cos πœƒ,
𝑦 = π‘Ÿ sin πœƒ
can be applied to write a vertex
< r,t, cyl >
< r,t,z, cyl >
// this is the standard form
2
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
Also, the spherical coordinate (π‘Ÿ, πœ‘, πœƒ) defined as
π‘₯ = π‘Ÿsinπœ‘ cos πœƒ,
𝑦 = π‘Ÿsinπœ‘ sin πœƒ,
𝑧 = π‘Ÿ cos πœ‘
can be utilized to write a vertex
< R,P,T, sph >
// this is the standard
β–  Reading Coordinate System. Any point in the global Cartesian
coordinate can be read from the cylindrical and spherical coordinate systems by
< x,y,z >.cyl
< x,y,z >.sph
to get (π‘Ÿ, πœƒ, 𝑧) and (π‘Ÿ, πœ‘, πœƒ) values. For example,
#> < 1,1,1 >.cyl ;
#> < 1,1,1 >.sph ;
result in
ans = <
ans = <
1.414
1.732
0.7854
0.9553
1 >
0.7854 >
At present, it is noteworthy that the angle is written in radian instead of degree.
Of course, such a regulation can be easily changed as can be seen later.
β–  Conversion between Coordinate Systems. Any vertex written in one
coordinate system can be converted to a vertex in another coordinate system by
<
<
<
<
double,double,double, w_csys > .r_csys
vertex, w_csys > .r_csys
double,double,double, wA_csys[i] > .rA_csys[j]
vertex, wA_csys[i] > .rA_csys[j]
where w_csys represents a writing coordinate system, and r_csys a reading
coordinate system. In addition, wA_csys represents an array of ‘csys’. Then,
3
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
one can easily note that whenever the writing and reading coordinate systems
are identical, e.g.
< double,double,double,
< double,double,double,
w_csys > . w_csys
wA_csys[i] > . rA_csys[j]
are always the same as
< double,double,double >
The notation in Cemmath is very concise and thus will help users to exploit
various coordinate systems with ease.
β–  Coordiate Values. Any vertex can be interpreted in one of the Cartesian,
cylindrical/polar and spherical coordinates. In Cemmath, the specific coordinate
values are designated
v.x, v.y, v.z
v.r, v.t, v.z
// ( x, y, z ) for the Cartesian coordinate
// ( r, t, z ) for the cylindrical coordinate
v.R, v.P, v.T
// ( R, P, T ) for the spherical coordinate
It should be noted that the angle system is by default ‘csys.rad’ based on the
radian system in both reading and writing modes. The angle system can be
changed by employing degree coordinate system, i.e. ‘csys.deg’ as can be seen
later. An example is as follows.
%>
#>
#>
#>
coordinate values
v = < 1,1,1 > ;
v.x; v.y; v.z; // Cartesian
v.r; v.t; v.z; // cylindrical
#> v.R; v.P; v.T; // spherical
v = <
1
1
ans =
1
ans =
1
ans =
1
ans
ans
ans
ans
=
=
=
=
1 >
1.4142136
0.78539816
1
1.7320508
4
[100] 013
ans =
ans =
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
0.95531662
0.78539816
It is also possible to change the specific coordinate value. For example,
%> coordinate values
#> v = < 1,1,1 > ;
#> v.R = 3 ;
v = <
1
v = <
1.732
1
1.732
1 >
1.732 >
Note that changing the radius in the spherical coordinate does not change the
azimuthal and the cone angles. This is true for all other coordinate values, i.e.
only one spatial coordinate can be changed by component assignment in each
coordinate system.
β–  Compound Operations. Compound operations for the vertex elements
are very useful to manipulate the positions at the three-dimensional space. For
example, a vertex at (π‘Ÿ, πœƒ, 𝑧) can be moved to (π‘Ÿ, πœƒ + Δπœƒ, 𝑧) just by ‘v.t +=
dt’.
Available compound operations are
v.x += d
v.y += d
v.z += d
v.x -= d
v.y -= d
v.z -= d
v.x *= d
v.y *= d
v.z *= d
v.x /= d
v.y /= d
v.z /= d
v.x ^= d
v.y ^= d
v.z ^= d
v.r
v.t
v.R
v.P
v.T
v.r
v.t
v.R
v.P
v.T
v.r
v.t
v.R
v.P
v.T
v.r
v.t
v.R
v.P
v.T
v.r
v.t
v.R
v.P
v.T
+=
+=
+=
+=
+=
d
d
d
d
d
-=
-=
-=
-=
-=
d
d
d
d
d
*=
*=
*=
*=
*=
d
d
d
d
d
Examples are
%> compound operations
#> csys.rad;
#>
#>
#>
#>
vx = < 2,0.5,1, sph >;; vx.sph ;
v = vx;; v.R += 1;; v.sph ;
v = vx;; v.P += 1;; v.sph ;
v = vx;; v.T += 1;; v.sph ;
5
/=
/=
/=
/=
/=
d
d
d
d
d
^=
^=
^=
^=
^=
d
d
d
d
d
[100] 013
vx = <
ans = <
ans = <
ans = <
ans = <
Chapter 13 Vertex and Coordinate System,
0.5181
2
3
2
2
0.8068
0.5
0.5
1.5
0.5
Tutorial by www.msharpmath.com
1.755 >
1 >
1 >
1 >
2 >
Section 13-2 Operations for Vertices
β–  Binary Operations. Binary operations between vertices are discussed by
using two vertices
a = < a1, a2, a3 >
b = < b1, b2, b3 >
Then, binary operations between vertices are defined
a + b = < a1+b1, a2+b2, a3+b3 > = a .+ b
a – b = < a1-b1, a2-b2, a3-b3 > = a .- b
a * b = a1*b1 + a2*b2 + a3*b3
a ^ b = < a2*b3-a3*b2, a3*b1-a1*b3, a1*b2-a2*b1 >
a .* b = < a1*b1, a2*b2, a3*b3 >
a .^ b = < a1^b1, a2^b2, a3^b3 >
a ./ b = < a1/b1, a2/b2, a3/b3 >
// element-by-element
a . \ b = < b1/a1, b2/a2, b3/a3 >
Examples are
%> binary operations
#> <1,2,3> + <3,4,5> ;
ans = <
4
6
8>
4
-2 >
#> <1,2,3> * <3,4,5> ;
ans =
26
#> <1,2,3> ^ <3,4,5> ;
ans = <
-2
6
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
Note that multiplication of two vertices (i.e. 3D vectors) produces ‘double’ data
not of ‘vertex’. Also, note that the hat ‘^’ operator corresponds to the cross
product between vertices. These operations are consistent with the typical
vector operations
𝐚 ⋅ 𝐛 = π‘Ž1 𝑏1 + π‘Ž2 𝑏2 + π‘Ž3 𝑏3
π’Š
𝒋
π’Œ
𝐚 × π› = |π‘Ž1 π‘Ž2 π‘Ž3 |
𝑏1 𝑏2 𝑏3
= 𝐒(π‘Ž2 𝑏3 − π‘Ž3 𝑏2 ) + 𝐣(π‘Ž3 𝑏1 − π‘Ž1 𝑏3 ) + 𝐀(π‘Ž1 𝑏2 − π‘Ž2 𝑏1 )
In particular, the relational operators are defined
a
a
a
a
a
== b
!= b
> b
< b
>= b
a <= b
is
is
is
is
is
true
true
true
true
true
is true
if
if
if
if
if
|a1-b1|+|a2-b2|+|a3-b3| <= meps
|a1-b1|+|a2-b2|+|a3-b3| > meps
a1 > b1, a2 > b2, a3 > b3
a1 < b1, a2 < b2, a3 < b3
a1 >= b1, a2 >= b2, a3 >= b3
if a1 <= b1, a2 <= b2, a3 <= b3
where ‘meps’ is a priori prescribed small number. A few examples are as
follows.
%>
#>
#>
#>
#>
binary operations
<1,2,3> == <3,4,5> ;
<1,2,3> != <3,4,5> ;
<1,2,3> > <3,4,5> ;
<1,2,3> < <3,4,5> ;
#> <1,2,3> >= <3,4,5> ;
#> <1,2,3> <= <3,4,5> ;
ans =
0
ans =
1
ans =
0
ans =
ans =
ans =
1
0
1
7
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
β–  Binary Operations with ‘double’ Data. Binary operations between
vertices and double data are performed by upgrading ‘double’ to ‘vertex’, i.e. a
double data is considered to be a vertex with all the identical components. In
summary, bindary operations for vertices are listed as follows
v1
v1
v1
v1
v1
v1
==
!=
>
<
>=
<=
v2
v2
v2
v2
v2
v2
v1
v1
v1
v1
v1
v1
==
!=
>
<
>=
<=
v1 ^ v2
v1
v1
v1
v1
+
*
/
v1 .+ v2
v1 .- v2
v1 .* v2
v1 .+ s
v1 .- s
v1 .* s
s .+ v2
s .- v2
s .* v2
v1 .^ v2
v1 .^ s
s .^ v2
v1 ./ v2
v1 ./ s
v1 + v2
v1 - v2
v1 * v2
s
s
s
s
s
s
s
s
s
s
s
s
s
s
s
s
==
!=
>
<
>=
<=
v2
v2
v2
v2
v2
v2
s + v2
s - v2
s * v2
s \ v2
v1 .\ v2
s .\ v2
β–  Compound Operations. Compound operations for vertices are as
follows.
v += v2
v -= v2
v += s
v -= s
v ^= v2
v *= s
v /= s
β–  Tensor Operations. Vectors in physics, e.g. force, can be also described
by vertices in 3D space. In Cemmath, the second-order tensor in physics is
treated as a 3 × 3 matrix. Then, two vertices, or equivalently two vectors
a = < a1, a2, a3 >
b = < b1, b2, b3 >
8
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
can be used to define tensor product and tensor division
a ** b = [ a1*b1, a2*b1, a3*b1 ]
[ a1*b2, a2*b2, a3*b2 ]
[ a1*b3, a2*b3, a3*b3 ]
a %% b = [ a1/b1, a2/b1, a3/b1 ]
[ a1/b2, a2/b2, a3/b2 ]
[ a1/b3, a2/b3, a3/b3 ]
These operators can be utilized to calculate, for example
𝑑𝐹1
𝑑𝐴1
𝑑𝐹𝑗
𝑑𝐅
𝑑𝐹1
𝛔=
=(
)=
𝑑𝐀
𝑑𝐴𝑗
𝑑𝐴2
𝑑𝐹1
[𝑑𝐴3
𝑑𝐹2
𝑑𝐴1
𝑑𝐹2
𝑑𝐴2
𝑑𝐹2
𝑑𝐴3
𝑑𝐹3
𝑑𝐴1
𝑑𝐹3
𝑑𝐴2
𝑑𝐹3
𝑑𝐴3 ]
since we can write the above as ‘dF %% dA’.
In addition, the typical multiplication in continuum mechanics such as
‘vector*tensor’ and ‘tensor*vector’ can be implemented in Cemmath
‘vertex’ * ‘matrix’
‘matrix’ * ‘vertex’
which represent the following operations
𝑑𝐀 ⋅ 𝛔 = ( 𝐒𝑑𝐴1 + 𝐣𝑑𝐴2 + 𝐀𝑑𝐴3 )
⋅ (𝐒𝐒𝜎11 + 𝐒𝐣𝜎12 + 𝐒𝐀𝜎13 + 𝐣𝐒𝜎21 + 𝐣𝐣𝜎22 + 𝐣𝐀𝜎23
+𝐀𝐒𝜎31 + 𝐀𝐣𝜎32 + 𝐀𝐀𝜎33 )
= 𝑑𝐴1 (𝐒𝜎11 + 𝐣𝜎12 + 𝐀𝜎13 ) + 𝑑𝐴2 (𝐒𝜎21 + 𝐣𝜎22 + 𝐀𝜎23 )
+𝑑𝐴3 (𝐒𝜎31 + 𝐣𝜎32 + 𝐀𝜎33 )
𝛔 ⋅ 𝑑𝐀 = (𝐒𝐒𝜎11 + 𝐒𝐣𝜎12 + 𝐒𝐀𝜎13 + 𝐣𝐒𝜎21 + 𝐣𝐣𝜎22 + 𝐣𝐀𝜎23
+𝐀𝐒𝜎31 + 𝐀𝐣𝜎32 + 𝐀𝐀𝜎33 ) ⋅ ( 𝐒𝑑𝐴1 + 𝐣𝑑𝐴2 + 𝐀𝑑𝐴3 )
= 𝑑𝐴1 (𝐒𝜎11 + 𝐣𝜎21 + 𝐀𝜎31 ) + 𝑑𝐴2 (𝐒𝜎12 + 𝐣𝜎22 + 𝐀𝜎32 )
+𝑑𝐴3 (𝐒𝜎13 + 𝐣𝜎23 + 𝐀𝜎33 )
9
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
An example for tensor operations is given below.
%> tensor operations
#> I = < 1,0,0 >;; J = < 0,1,0 >;;
K = < 0,0,1 >;;
#> va = <1,2,3>; vb = <3,4,5>;
va = <
1
2
vb = <
3
4
3 >
5 >
#> C = va ** vb ;
C =
[
[
[
3
4
5
6
8
10
9 ]
12 ]
15 ]
0.33333
0.25
0.2
0.66667
0.5
0.4
1 ]
0.75 ]
0.6 ]
#> D = va %% vb ;
D =
[
[
[
#> I * D; J * D; K * D;
ans = <
0.3333
ans = <
0.25
ans = <
0.2
0.6667
0.5
0.4
1 >
0.75 >
0.6 >
#> D * I; D * J; D * K;
ans = <
0.3333
ans = <
0.6667
ans = <
1
0.25
0.5
0.75
0.2 >
0.4 >
0.6 >
Section 13-3 Member Functions for Vertices
β–  Member Functions. Avaliable member functions
.xrot(t)
.yrot(t)
.zrot(t)
.xrotd(t)
rotation
rotation
rotation
rotation
around
around
around
around
the
the
the
the
x-axis
y-axis
z-axis
x-axis in degree
10
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
.yrotd(t)
.zrotd(t)
.unit
.trun
.plot
.abs/norm
rotation around the y-axis in degree
rotation around the z-axis in degree
normalize by the magnitude
truncate
plot in 3D space
the same as .R
.symm(vp)
symmetric position with respect to ‘vertex’ vp
are employed to treat vertices in a variety of ways.
Section 13-4 Class ‘csys’
In this section, we discuss the class ‘csys’ to describe local coordinate
system in contrast to the global coordinate systems.
β–  Principal Coordinate Systems. The global principal coordinate systems
(i.e. the rectangular, cylindrical and spherical) should be treated as special
‘csys’. This allows that
%> (M #Example 13-4-1) principal spherical system
#> csys.sph;
to represent
ans =
'spherical' local coordinate system
origin
= <
0
dir cosine
= [
1
[
0
[
0
0
0
1
0 >
0 ]
0 ]
0
1 ]
β–  Local Coordinate Systems. A local coordinate system is composed of
two elements with respect to the global Cartesian coordinate. The first is the
origin, and the second is the direction cosines. In the global Cartesian
coordinate, the direction cosine of the π‘₯-axis of a local coordinate can be
written as 𝐝1 = (𝑑11 , 𝑑21 , 𝑑31 ). Similary, the 𝑦 and 𝑧 axes can be denoted by
𝐝2 = (𝑑12 , 𝑑22 , 𝑑32 ) and 𝐝3 = (𝑑13 , 𝑑23 , 𝑑33 ) , respectively. Also, the
11
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
orthogonality requires that 𝐝𝑖 ⋅ 𝐝𝑗 = 𝛿𝑖𝑗 whenever 𝛿𝑖𝑗 is the Kronecker delta.
Then, the mathematical definition of a local orthogonal coordinate system is
π‘₯0
𝑑11
𝑋
[π‘Œ ] = [𝑦0 ] + [𝑑21
𝑧0
𝑑31
𝑍
𝑑12
𝑑22
𝑑32
𝑑13 π‘₯
𝑑23 ] [𝑦]
𝑑33 𝑧
where the origin of a local coordinate system is represented by a vertex, and the
direction cosine of a local coordinate system is represented by a matrix of
dimension 3 × 3. Then, the coordinate (π‘₯, 𝑦, 𝑧) in the local coordinate can be
identified as the coordinate (𝑋, π‘Œ, 𝑍) in the global Cartesian coordinate.
The syntax to create a local coordinate system with an origin at vertex
‘vorg’ is
csys.rec ( vorg, vn1,vn2 )
csys.cyl ( vorg, vn1,vn2 )
csys.sph ( vorg, vn1,vn2 )
or equivalently
csys ( 1, vorg, vn1,vn2 )
csys ( 2, vorg, vn1,vn2 )
csys ( 3, vorg, vn1,vn2 )
where the integers 1,2 and 3 denote the rectangular, cylindrical and spherical
coordinate, respectively. In the above, two vertices ‘vn1,vn2’ are used to
generate direction cosines
𝐝1 =
𝐧1
,
|𝐧1 |
𝐝2 =
𝐧1 × π§2
,
|𝐧1 × π§2 |
𝐝2 = 𝐝3 × π1
β–  An Example of Local Coordinate Systems. Let us consider a simple
example of a local coordinate system by the following Cemmath command
%> local coordinate system
#> cs1 = csys.cyl( <3,1>, <1,1>, <-1,2>);
cs1 =
'cylindrical' local coordinate system
12
[100] 013
Chapter 13 Vertex and Coordinate System,
origin
dir cosine
= <
= [
[
[
3
0.70711
0.70711
0
Tutorial by www.msharpmath.com
1
-0.70711
0.70711
0
0 >
0 ]
0 ]
1 ]
This local coordinate system is shown in Figure 1.
Figure 1 A local coordinate system
Then, it is easy to find that the point P(1,1,0) in the global coordinate is
interpreted to be (2,3π/4,0) in the local cylindrical coordinate system. Also
the point Q(2,2,0) in the global coordinate is interpreted to be (√2, π/2,0) in
the local cylindrical coordinate system. This can be confirmed by
#> <1,1,0>.cs1 ;
// <2, pi*3/4, 0>
#> <2,2,0>.cs1 ;
// <1.414, pi/2, 0>
#> <sqrt(2),pi/2,0, cs1> ; // <2, 2, 0>
ans = <
2
2.356
0 >
ans = <
1.414
1.571
0 >
ans = <
2
2
0 >
In the above, writing and reading with respect to a local coordinate system are
treated very concisely.
β–  Class Functions of ‘csys’. Several class functions are
13
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
csys.rec
csys.cyl
csys.sph
csys.deg
csys.rad
csys.pass180/passpi
//
//
//
//
//
//
csys.rectangular, csys.cart, csys.cartesian
csys.cylindrical, csys.polar
csys.spherical
angles in degree
angles in radian (default)
pass 180 degree, i.e. 0 <= theta < 360
csys.pass0
// pass 0 degree, i.e. -180 < theta <= 180
When ‘csys.deg’ is executed, the degree is adopted to be the angle system.
This can be confirmed by
%> angle system
#> csys.deg; < 1,45,0, cyl >;
#> csys.rad; < 1,pi/4,0, cyl >;
// angle in degree. csys.deg is activated
ans = <
0.7071
0.7071
0 >
// angle in radian.
ans = <
0.7071
0 >
csys.rad is activated
0.7071
The range of angle can be defined in two different ways
0 ≤ πœƒ < 2πœ‹,
−πœ‹ < πœƒ ≤ πœ‹
The first case passes πœƒ = πœ‹ line and the second case passes πœƒ = 0 line. In this
regard, two commands ‘csys.pass180/passpi’ and ‘csys.pass0’ can be used
to select the range of angle. The default system is ‘csys.pass0’, i.e. −πœ‹ < πœƒ ≤
πœ‹ is assumed. This argument can be confirmed by
%>
#>
#>
//
angle range
csys.pass180; < 1,-1,0 >.cyl;
csys.pass0;
< 1,-1,0 >.cyl;
angle range, 0 <= radian < 2*pi is activated
ans = <
1.414
5.498
0 >
// angle range, -pi < radian <= pi, is activated
ans = <
1.414
-0.7854
0 >
β–  Member Functions of ‘csys’. Several member functions are
.plot
// plot coordinate system
14
[100] 013
Chapter 13 Vertex and Coordinate System,
.org
.cos
Tutorial by www.msharpmath.com
// origin of a local coordinate system
// direction cosine of a a local coordinate system
The origin of a local coordinate system can be changed via member function
‘org’. An example is as follows.
%> change origin
#> cs2 = csys.cyl( <3,1>, <1,1>, <-1,2>);
#> cs2.org = < 5,4,7 >;
#> cs2;
cs2 =
'cylindrical' local coordinate system
origin
= <
3
1
dir cosine
= [
0.70711
-0.70711
[
0.70711
0.70711
[
0
0
ans = <
cs2 =
5
4
7 >
'cylindrical' local coordinate system
origin
= <
5
4
dir cosine
= [
0.70711
-0.70711
[
[
0 >
0 ]
0 ]
1 ]
0.70711
0
7 >
0 ]
0.70711
0
0 ]
1 ]
However, direction cosine cannot be modified since the orthogonality of the
direction cosine need to be preserved. In later version of Cemmath, we will
upgrade this part. Referring can be done by
%> change origin
#> cs2 = csys.cyl( <3,1>, <1,1>, <-1,2>);
#> cs2.cos;
ans =
[
[
[
0.70711
0.70711
0
-0.70711
0.70711
0
Section 13-5 Application Examples
15
0 ]
0 ]
1 ]
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
β–  Center of a Triangle. A circle enclosing a triangle is found by vertex
operations as follows.
%> A circle enclosing a triangle
#> vA=<3,5,7>; vB=<-1,2,-5>; vC=<4,-6,1>;
#> Radius = 0;
#> vG=(vA+vB+vC)/3; // geometric center
va = vB-vA;
vb = vC-vA;
vn = va^vb;
vx = vn^va;
dt = 0.5*((vb-va)*vb)/(vx*vb);
vr = 0.5*va+dt*vx;
//
vr = va/2+t*vx, vr-(vb/2) should be orthogoanal to vb
if(Radius > 1.e-10) {
dt = sqrt( (Radius*Radius-vr*vr)/(vn*vn) );
vr = vr + dt*vn;
}
#> vcen = vA+vr ;
#> (vcen-vA).abs;
#> (vcen-vB).abs;
#> (vcen-vC).abs ;
// 7.11111
vcen = <
1.99
0.8125
ans =
7.1111817
ans =
7.1111817
ans =
7.1111817
1.342 >
At the end of commands, it is confirmed that the point ‘vcen’ is indeed the
center of a triangle.
β–  Array of Vertex. A number of vertices can be created by an array of
vertex, and they can be used to generate meshes. An example is to make an
annular mesh as follows.
%> Vertex array to generate annular mesh
16
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
#> vertex V[50];
#> csys.deg;
#> for.i(0,4) {
r = 1 + 0.1*i;;
for.j(0,9) {
t = 36*j;;
V[10*i+j] = < r,t, cyl >;;
}
}
#> V;
V = vertex [50]
[0]
[1]
[2]
[3]
=
=
=
=
<
<
<
<
1
0.809
0.309
-0.309
0
0.5878
0.9511
0.9511
0
0
0
0
>
>
>
>
…
[18] = <
[19] = <
0.3399
-1.046
0.8899
-0.6466
and more ... (50 elements)
0 >
0 >
Section 13-6 Summary
β–  Class Functions of ‘vertex’.
vertex.format(“string”)
β–  Conversion between Coordinate Systems. Any vertex written in one
coordinate system can be converted to a vertex in another coordinate system by
< double,double,double, w_csys > .r_csys
< vertex, w_csys > .r_csys
β–  Member Functions of ‘vertex’.
.xrot(t)
.yrot(t)
.zrot(t)
.xrotd(t)
rotation
rotation
rotation
rotation
around
around
around
around
the
the
the
the
x-axis
y-axis
z-axis
x-axis in degree
17
[100] 013
Chapter 13 Vertex and Coordinate System,
Tutorial by www.msharpmath.com
.yrotd(t)
.zrotd(t)
.unit
.trun
.plot/plot3
.abs/norm
rotation around the y-axis in degree
rotation around the z-axis in degree
normalized by the magnitude
truncate
plot in 3D space
the same as .R
.symm(vp)
symmetric position with respect to ‘vertex’ vp
β–  Class Functions of ‘csys’.
csys.rec
csys.cyl
csys.sph
csys.deg
csys.rad
csys.pass180/passpi
csys.pass0
// csys.rectangular, csys.cart, csys.cartesian
// csys.cylindrical, csys.polar
// csys.spherical
// angles in degree
// angles in radian (default)
// pass 180 degree, i.e. 0 <= theta < 360
// pass 0 degree, i.e. -180 < theta <=180
csys.rec ( vorg, vn1,vn2 )
csys.cyl ( vorg, vn1,vn2 )
csys.sph ( vorg, vn1,vn2 )
β–  Member Functions of ‘csys’.
.plot/plot3
.org
// plot coordinate system
// origin of a local coordinate system
.cos
// direction cosine of a local coordinate system
//---------------------------------------------------------------------// end of file
//----------------------------------------------------------------------
18
Download