Exemplo n.º 1
0
// PlotRefOct plots reference failure criterions in octahedral plane:
//  Drucker-Prager and Mohr-Circles
func PlotRefOct(φ, σc float64, withExtCircle bool) {
	if φ > 0 {
		sφ := math.Sin(φ * math.Pi / 180.0)
		μmax := 2.0 * SQ2 * sφ / (3.0 - sφ)
		μmin := 2.0 * SQ2 * sφ / (3.0 + sφ)
		Rmax := μmax * σc
		Rmin := μmin * σc
		d30 := math.Pi / 6.0
		xa := -Rmin * math.Cos(d30)
		ya := Rmin * math.Sin(d30)
		xb := -Rmax * math.Cos(d30)
		yb := -Rmax * math.Sin(d30)
		plt.Plot([]float64{xb, xa, 0, -xa, -xb, 0, xb}, []float64{yb, ya, Rmax, ya, yb, -Rmin, yb}, "'grey', ls='-'")
		if withExtCircle {
			plt.Circle(0, 0, Rmin, "ec='grey'")
		}
		plt.Circle(0, 0, Rmax, "ec='grey'")
	}
}
Exemplo n.º 2
0
// PlotStar plots star with normalised OVAs
func (o *Optimiser) PlotStar() {
	nf := o.Nf
	dθ := 2.0 * math.Pi / float64(nf)
	θ0 := 0.0
	if nf == 3 {
		θ0 = -math.Pi / 6.0
	}
	for _, ρ := range []float64{0.25, 0.5, 0.75, 1.0} {
		plt.Circle(0, 0, ρ, "ec='gray',lw=0.5,zorder=5")
	}
	arrowM, textM := 1.1, 1.15
	for i := 0; i < nf; i++ {
		θ := θ0 + float64(i)*dθ
		xi, yi := 0.0, 0.0
		xf, yf := arrowM*math.Cos(θ), arrowM*math.Sin(θ)
		plt.Arrow(xi, yi, xf, yf, "sc=10,st='->',lw=0.7,zorder=10,clip_on=0")
		plt.PlotOne(xf, yf, "'k+', ms=0")
		xf, yf = textM*math.Cos(θ), textM*math.Sin(θ)
		plt.Text(xf, yf, io.Sf("%d", i), "size=6,zorder=10,clip_on=0")
	}
	X, Y := make([]float64, nf+1), make([]float64, nf+1)
	clr := false
	neg := false
	step := 1
	count := 0
	colors := []string{"m", "orange", "g", "r", "b", "k"}
	var ρ float64
	for i, sol := range o.Solutions {
		if sol.Feasible() && sol.FrontId == 0 && i%step == 0 {
			for j := 0; j < nf; j++ {
				if neg {
					ρ = 1.0 - sol.Ova[j]/(o.RptFmax[j]-o.RptFmin[j])
				} else {
					ρ = sol.Ova[j] / (o.RptFmax[j] - o.RptFmin[j])
				}
				θ := θ0 + float64(j)*dθ
				X[j], Y[j] = ρ*math.Cos(θ), ρ*math.Sin(θ)
			}
			X[nf], Y[nf] = X[0], Y[0]
			if clr {
				j := count % len(colors)
				plt.Plot(X, Y, io.Sf("'k-',color='%s',markersize=3,clip_on=0", colors[j]))
			} else {
				plt.Plot(X, Y, "'r-',marker='.',markersize=3,clip_on=0")
			}
			count++
		}
	}
	plt.Equal()
	plt.AxisOff()
}
Exemplo n.º 3
0
// Draw draws grid
//  r   -- radius of circles
//  W   -- width of paths
//  dwt -- δwt for positioning text (w = W/2)
//  arrow_scale -- scale for arrows. use 0 for default value
func (o *Graph) Draw(dirout, fname string, r, W, dwt, arrow_scale float64,
	verts_lbls map[int]string, verts_fsz float64, verts_clr string,
	edges_lbls map[int]string, edges_fsz float64, edges_clr string) {
	if len(o.Verts) < 1 {
		return
	}
	xmin, ymin := o.Verts[0][0], o.Verts[0][1]
	xmax, ymax := xmin, ymin
	var lbl string
	for i, v := range o.Verts {
		if verts_lbls == nil {
			lbl = io.Sf("%d", i)
		} else {
			lbl = verts_lbls[i]
		}
		plt.Text(v[0], v[1], lbl, io.Sf("clip_on=0, color='%s', fontsize=%g, ha='center', va='center'", verts_clr, verts_fsz))
		plt.Circle(v[0], v[1], r, "clip_on=0, ec='k', lw=0.8")
		xmin, ymin = utl.Min(xmin, v[0]), utl.Min(ymin, v[1])
		xmax, ymax = utl.Max(xmax, v[0]), utl.Max(ymax, v[1])
	}
	if W > 2*r {
		W = 1.8 * r
	}
	w := W / 2.0
	xa, xb := make([]float64, 2), make([]float64, 2)
	xc, dx := make([]float64, 2), make([]float64, 2)
	mu, nu := make([]float64, 2), make([]float64, 2)
	xi, xj := make([]float64, 2), make([]float64, 2)
	l := math.Sqrt(r*r - w*w)
	var L float64
	if arrow_scale <= 0 {
		arrow_scale = 20
	}
	for k, e := range o.Edges {
		L = 0.0
		for i := 0; i < 2; i++ {
			xa[i] = o.Verts[e[0]][i]
			xb[i] = o.Verts[e[1]][i]
			xc[i] = (xa[i] + xb[i]) / 2.0
			dx[i] = xb[i] - xa[i]
			L += dx[i] * dx[i]
		}
		L = math.Sqrt(L)
		mu[0], mu[1] = dx[0]/L, dx[1]/L
		nu[0], nu[1] = -dx[1]/L, dx[0]/L
		for i := 0; i < 2; i++ {
			xi[i] = xa[i] + l*mu[i] - w*nu[i]
			xj[i] = xb[i] - l*mu[i] - w*nu[i]
			xc[i] = (xi[i]+xj[i])/2.0 - dwt*nu[i]
		}
		plt.Arrow(xi[0], xi[1], xj[0], xj[1], io.Sf("st='->', sc=%g", arrow_scale))
		if edges_lbls == nil {
			lbl = io.Sf("%d", k)
		} else {
			lbl = edges_lbls[k]
		}
		plt.Text(xc[0], xc[1], lbl, io.Sf("clip_on=0, color='%s', fontsize=%g, ha='center', va='center'", edges_clr, edges_fsz))
	}
	xmin -= r
	xmax += r
	ymin -= r
	ymax += r
	plt.AxisOff()
	plt.Equal()
	plt.AxisRange(xmin, xmax, ymin, ymax)
	plt.SaveD(dirout, fname)
}
Exemplo n.º 4
0
func Test_cubiceq04(tst *testing.T) {

	//verbose()
	chk.PrintTitle("cubiceq03. y(x) = x³ - 3xr²/4 - r³cos(3α)/4")

	doplot := false
	r := 1.0
	np := 41
	var X, Y []float64
	if doplot {
		X = utl.LinSpace(-1.2*r, 1.2*r, np)
		Y = make([]float64, np)
		plt.SetForPng(0.8, 400, 200)
	}

	π := math.Pi
	a := 0.0
	b := -3.0 * r * r / 4.0
	colors := []string{"red", "green", "blue"}
	for k, α := range []float64{0, π / 6.0, π / 3.0} {
		c := -math.Pow(r, 3.0) * math.Cos(3.0*α) / 4.0
		for i, x := range X {
			Y[i] = x*x*x + a*x*x + b*x + c
		}
		x1, x2, x3, nx := EqCubicSolveReal(a, b, c)
		io.Pforan("\na=%v b=%v c=%v\n", a, b, c)
		io.Pfcyan("nx=%v\n", nx)
		io.Pfcyan("x1=%v x2=%v x3=%v\n", x1, x2, x3)
		if k == 0 {
			chk.IntAssert(nx, 2)
			chk.Scalar(tst, "x1", 1e-17, x1, r)
			chk.Scalar(tst, "x2", 1e-17, x2, -r/2.0)
		}
		if k == 1 {
			chk.IntAssert(nx, 3)
			chk.Scalar(tst, "x1", 1e-15, x1, r*math.Cos(α+2.0*π/3.0))
			chk.Scalar(tst, "x2", 1e-17, x2, r*math.Cos(α))
			chk.Scalar(tst, "x3", 1e-15, x3, r*math.Cos(α-2.0*π/3.0))
		}
		if k == 2 {
			chk.IntAssert(nx, 2)
			chk.Scalar(tst, "x1", 1e-17, x1, -r)
			chk.Scalar(tst, "x2", 1e-17, x2, r/2.0)
		}
		if doplot {
			switch nx {
			case 1:
				plt.Plot([]float64{x1}, []float64{0}, io.Sf("'ko', color='%s'", colors[k]))
			case 2:
				plt.Plot([]float64{x1, x2}, []float64{0, 0}, io.Sf("'ko', color='%s'", colors[k]))
			case 3:
				plt.Plot([]float64{x1, x2, x3}, []float64{0, 0, 0}, io.Sf("'ko', color='%s'", colors[k]))
			}
			plt.Plot(X, Y, io.Sf("color='%s', label='%s'", colors[k], plt.TexPiRadFmt(α)))
		}
	}
	if doplot {
		plt.Circle(0, 0, r, "ec='black'")
		plt.Equal()
		plt.Gll("x", "y", "")
		plt.SaveD("/tmp", "fig_cubiceq04.png")
	}
}