Reputation: 395
I have three vectors X, Y, Z originated from O(0, 0, 0):
1.02 4.30 1.50 0 ! X
5.33 5.05 5.60 0 ! Y
3.40 6.00 8.05 0 ! Z
I would like to plot (1) these vectors, (2) a box created from these three vectors, and (3) a point arbitrarily inside the box like the following picture. Can you show me how?
set terminal postscript eps enhanced
set mapping cartesian
set output 'box_with_point.eps'
splot vectors.txt using 1:2:3:4:5:6 with vectors filled head lw 3
Upvotes: 1
Views: 108
Reputation: 25714
What you have to do is obvious: besides your 3 vectors you have to plot 9 additional lines. However, this not too obvious how to do this with gnuplot. Check the following example:
Code:
### plot unit cell
reset session
set view equal xyz
set view 80,72, 1.5
set xyplane relative 0
set border 4095
$Data <<EOD
1.02 4.30 1.50 0 ! X
5.33 5.05 5.60 0 ! Y
3.40 6.00 8.05 0 ! Z
EOD
$myPoint <<EOD
5.0 7.5 8.0
EOD
array X[3]
array Y[3]
array Z[3]
getXYZ(r) = (X[r+1]=$1, Y[r+1]=$2, Z[r+1]=$3)
myX(n) = X[(int($0)+n)%3+1]
myY(n) = Y[(int($0)+n)%3+1]
myZ(n) = Z[(int($0)+n)%3+1]
set key noautotitle
splot $Data u (getXYZ(int($0)),0):(0):(0):1:2:3:0 w vec lc var lw 2, \
$myPoint u 1:2:3 w p pt 7 ps 2 lc "red", \
for [i=1:2] $Data u 1:2:3:(myX(i)):(myY(i)):(myZ(i)) w vec lc "grey" lw 2 nohead, \
$Data u ($1+myX(1)):($2+myY(1)):($3+myZ(1)):(myX(2)):(myY(2)):(myZ(2)) w vec lc "grey" lw 2 nohead
### end of code
Result:
Addition:
Here is another approach which is maybe easier to follow and which simplifying the actual plot command. It's necessary to have the data in a datablock.
Code: (result same as above)
### plot unit cell
reset session
set view equal xyz
set view 80,72, 1.5
set xyplane relative 0
set border 4095
$Data <<EOD
1.02 4.30 1.50 0 ! X
5.33 5.05 5.60 0 ! Y
3.40 6.00 8.05 0 ! Z
EOD
$myPoint <<EOD
5.0 7.5 8.0
EOD
Value(row,col) = real(word($Data[row],col))
Xx = Value(1,1)
Xy = Value(1,2)
Xz = Value(1,3)
Yx = Value(2,1)
Yy = Value(2,2)
Yz = Value(2,3)
Zx = Value(3,1)
Zy = Value(3,2)
Zz = Value(3,3)
set print $UnitCell
print sprintf("%g %g %g", 0 , 0 , 0)
print sprintf("%g %g %g", Xx , Xy , Xz)
print sprintf("%g %g %g", Xx+Yx, Xy+Yy, Xz+Yz)
print sprintf("%g %g %g", Yx , Yy , Yz)
print sprintf("%g %g %g", 0 , 0 , 0)
print ""
print sprintf("%g %g %g", Zx , Zy , Zz)
print sprintf("%g %g %g", Xx+Zx , Xy+Zy , Xz+Zz)
print sprintf("%g %g %g", Xx+Yx+Zx, Xy+Yy+Zy, Xz+Yz+Zz)
print sprintf("%g %g %g", Yx+Zx , Yy+Zy , Yz+Zz)
print sprintf("%g %g %g", Zx , Zy , Zz)
set print
set key noautotitle
splot $myPoint u 1:2:3 w p pt 7 ps 2 lc "red", \
$UnitCell w l lc "grey" lw 2, \
$Data u (0):(0):(0):1:2:3:0 w vec lc var lw 2
### end of code
Upvotes: 1