本文整理匯總了Golang中github.com/mumax/3/data.Slice.Vectors方法的典型用法代碼示例。如果您正苦於以下問題:Golang Slice.Vectors方法的具體用法?Golang Slice.Vectors怎麽用?Golang Slice.Vectors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mumax/3/data.Slice
的用法示例。
在下文中一共展示了Slice.Vectors方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: normalize
func normalize(f *data.Slice) {
a := f.Vectors()
maxnorm := 0.
for i := range a[0] {
for j := range a[0][i] {
for k := range a[0][i][j] {
x, y, z := a[0][i][j][k], a[1][i][j][k], a[2][i][j][k]
norm := math.Sqrt(float64(x*x + y*y + z*z))
if norm > maxnorm {
maxnorm = norm
}
}
}
}
factor := float32(1 / maxnorm)
for i := range a[0] {
for j := range a[0][i] {
for k := range a[0][i][j] {
a[0][i][j][k] *= factor
a[1][i][j][k] *= factor
a[2][i][j][k] *= factor
}
}
}
}
示例2: On
// Render on existing image buffer. Resize it if needed
func On(img *image.RGBA, f *data.Slice, fmin, fmax string, arrowSize int, colormap ...color.RGBA) {
dim := f.NComp()
switch dim {
default:
log.Fatalf("unsupported number of components: %v", dim)
case 3:
drawVectors(img, f.Vectors(), arrowSize)
case 1:
min, max := extrema(f.Host()[0])
if fmin != "auto" {
m, err := strconv.ParseFloat(fmin, 32)
if err != nil {
util.Fatal("draw: scale:", err)
}
min = float32(m)
}
if fmax != "auto" {
m, err := strconv.ParseFloat(fmax, 32)
if err != nil {
util.Fatal("draw: scale:", err)
}
max = float32(m)
}
if min == max {
min -= 1
max += 1 // make it gray instead of black
}
drawFloats(img, f.Scalars(), min, max, colormap...)
}
}
示例3: scale
func scale(f *data.Slice, factor float32) {
a := f.Vectors()
for i := range a[0] {
for j := range a[0][i] {
for k := range a[0][i][j] {
a[0][i][j][k] *= factor
a[1][i][j][k] *= factor
a[2][i][j][k] *= factor
}
}
}
}
示例4: normpeak
func normpeak(f *data.Slice) {
a := f.Vectors()
maxnorm := 0.
for i := range a[0] {
for j := range a[0][i] {
for k := range a[0][i][j] {
x, y, z := a[0][i][j][k], a[1][i][j][k], a[2][i][j][k]
norm := math.Sqrt(float64(x*x + y*y + z*z))
if norm > maxnorm {
maxnorm = norm
}
}
}
}
scale(f, float32(1/maxnorm))
}
示例5: normalize
// normalize vector data to given length
func normalize(f *data.Slice, length float64) {
a := f.Vectors()
for i := range a[0] {
for j := range a[0][i] {
for k := range a[0][i][j] {
x, y, z := a[0][i][j][k], a[1][i][j][k], a[2][i][j][k]
norm := math.Sqrt(float64(x*x + y*y + z*z))
invnorm := float32(1)
if norm != 0 {
invnorm = float32(length / norm)
}
a[0][i][j][k] *= invnorm
a[1][i][j][k] *= invnorm
a[2][i][j][k] *= invnorm
}
}
}
}
示例6: renderSVGZ
func renderSVGZ(f *data.Slice, info data.Meta, out io.Writer) {
out2 := gzip.NewWriter(out)
defer out2.Close()
draw.SVG(out2, f.Vectors())
}
示例7: renderSVG
func renderSVG(f *data.Slice, info data.Meta, out io.Writer) {
draw.SVG(out, f.Vectors())
}