Per esercizio ho provato ad implementare la proiezione isometrica in GO partendo dalle istruzioni su Wikipedia
i calcoli matriciali sono i seguenti (in questo caso e' gia' impostata una rotazione di alfa di circa 35 gradi e beta di 45 gradi
package main
import (
"fmt"
"math"
"gonum.org/v1/gonum/mat"
)
func format(matrix mat.Matrix) {
formatted := mat.Formatted(matrix, mat.Prefix(""), mat.Squeeze())
fmt.Println(formatted)
}
import (
"fmt"
"math"
"gonum.org/v1/gonum/mat"
)
func format(matrix mat.Matrix) {
formatted := mat.Formatted(matrix, mat.Prefix(""), mat.Squeeze())
fmt.Println(formatted)
}
func isometrica(x,y,z float64) (float64,float64) {
xs := mat.NewDense(3, 3, []float64{math.Sqrt(3), 0, -math.Sqrt(3),
1, 2, 1,
math.Sqrt(2), -math.Sqrt(2), math.Sqrt(2)})
//format(xs)
w := mat.NewDense(3, 3,nil)
w.Scale(1/math.Sqrt(6),xs)
coordinate := mat.NewVecDense(3, []float64{x,y,z}) // e' gia' un vettore colonna
c := mat.NewVecDense(3, make([]float64, 3))
c.MulVec(w,coordinate)
pr := mat.NewDense(3, 3, []float64{1,0,0,0,1,0,0,0,1})
d := mat.NewVecDense(3, make([]float64, 3))
d.MulVec(pr,c)
return d.AtVec(1),d.AtVec(2)
}
func main() {
xi,yi := isometrica(0.0,0.0,0.0)
fmt.Printf("data: %f,%f\n", xi,yi)
xi,yi = isometrica(1.0,0.0,0.0)
fmt.Printf("data: %f,%f\n", xi,yi)
xi,yi = isometrica(0.0,1.0,0.0)
fmt.Printf("data: %f,%f\n", xi,yi)
xi,yi = isometrica(1.0,1.0,0.0)
fmt.Printf("data: %f,%f\n", xi,yi)
xi,yi = isometrica(0.0,0.0,2.0)
fmt.Printf("data: %f,%f\n", xi,yi)
xi,yi = isometrica(1.0,0.0,2.0)
fmt.Printf("data: %f,%f\n", xi,yi)
xi,yi = isometrica(0.0,1.0,2.0)
fmt.Printf("data: %f,%f\n", xi,yi)
xi,yi = isometrica(1.0,1.0,2.0)
fmt.Printf("data: %f,%f\n", xi,yi)
}