Ejemplo n.º 1
0
func plot_cone(α float64, preservePrev bool) {
	nu, nv := 11, 21
	l := 1.2
	r := math.Tan(α) * l
	S, T := utl.MeshGrid2D(0, l, 0, 2.0*PI, nu, nv)
	X := la.MatAlloc(nv, nu)
	Y := la.MatAlloc(nv, nu)
	Z := la.MatAlloc(nv, nu)
	u := make([]float64, 3)
	v := make([]float64, 3)
	L := rot_matrix()
	for j := 0; j < nu; j++ {
		for i := 0; i < nv; i++ {
			u[0] = S[i][j] * r * math.Cos(T[i][j])
			u[1] = S[i][j] * r * math.Sin(T[i][j])
			u[2] = S[i][j]
			la.MatVecMul(v, 1, L, u)
			X[i][j], Y[i][j], Z[i][j] = v[0], v[1], v[2]
		}
	}
	pp := 0
	if preservePrev {
		pp = 1
	}
	plt.Wireframe(X, Y, Z, io.Sf("color='b', lw=0.5, preservePrev=%d", pp))
}
Ejemplo n.º 2
0
func plot_convex(level float64, preservePrev bool) {
	X, Y := utl.MeshGrid2D(0, 1, 0, 1, NU, NV)
	Z := la.MatAlloc(NV, NU)
	for j := 0; j < NU; j++ {
		for i := 0; i < NV; i++ {
			Z[i][j] = level - math.Sqrt(X[i][j]) - math.Sqrt(Y[i][j])
			if Z[i][j] < -0.01 {
				Z[i][j] = math.NaN()
			}
		}
	}
	pp := 0
	if preservePrev {
		pp = 1
	}
	plt.Wireframe(X, Y, Z, io.Sf("color='k', lw=0.5, preservePrev=%d", pp))
}
Ejemplo n.º 3
0
func plot_sphere(preservePrev bool) {
	R := 1.0
	U, V := utl.MeshGrid2D(0, PI/2.0, 0, PI/2.0, NU, NV)
	X, Y, Z := la.MatAlloc(NV, NU), la.MatAlloc(NV, NU), la.MatAlloc(NV, NU)
	for j := 0; j < NU; j++ {
		for i := 0; i < NV; i++ {
			X[i][j] = R * math.Cos(U[i][j]) * math.Sin(V[i][j])
			Y[i][j] = R * math.Sin(U[i][j]) * math.Sin(V[i][j])
			Z[i][j] = R * math.Cos(V[i][j])
		}
	}
	pp := 0
	if preservePrev {
		pp = 1
	}
	plt.Wireframe(X, Y, Z, io.Sf("color='k', lw=0.5, preservePrev=%d", pp))
}
Ejemplo n.º 4
0
func plot_superquadric(a, b, c float64, preservePrev bool) {
	A, B, C := 2.0/a, 2.0/b, 2.0/c
	R := 1.0
	U, V := utl.MeshGrid2D(0, PI/2.0, 0, PI/2.0, NU, NV)
	X, Y, Z := la.MatAlloc(NV, NU), la.MatAlloc(NV, NU), la.MatAlloc(NV, NU)
	for j := 0; j < NU; j++ {
		for i := 0; i < NV; i++ {
			X[i][j] = R * cosX(U[i][j], A) * sinX(V[i][j], A)
			Y[i][j] = R * sinX(U[i][j], B) * sinX(V[i][j], B)
			Z[i][j] = R * cosX(V[i][j], C)
		}
	}
	pp := 0
	if preservePrev {
		pp = 1
	}
	plt.Wireframe(X, Y, Z, io.Sf("color='k', lw=0.5, preservePrev=%d", pp))
}
Ejemplo n.º 5
0
func plot_plane(preservePrev bool) {
	N := []float64{1, 1, 1}   // normal
	P := []float64{0.5, 0, 0} // point on plane
	d := -N[0]*P[0] - N[1]*P[1] - N[2]*P[2]
	X, Y := utl.MeshGrid2D(0, 0.5, 0, 0.5, NU, NV)
	Z := la.MatAlloc(NV, NU)
	for j := 0; j < NU; j++ {
		for i := 0; i < NV; i++ {
			Z[i][j] = (-d - N[0]*X[i][j] - N[1]*Y[i][j]) / N[2]
			if Z[i][j] < -0.01 {
				Z[i][j] = math.NaN()
			}
		}
	}
	pp := 0
	if preservePrev {
		pp = 1
	}
	plt.Wireframe(X, Y, Z, io.Sf("color='k', lw=0.5, preservePrev=%d", pp))
}