コード例 #1
0
ファイル: plot.go プロジェクト: bernhard-hofmann/GearGen
func plotInvCurve(g gear.Gear, canvas *svg.SVG) {
	var px []int
	var py []int
	var pyi []int
	var x, y float64
	var r, sr, ang float64
	var offsetAng float64
	br := g.GetBaseCircleDia() * factor / 2 // Base Radius
	or := g.GetOutsideDia() * factor / 2    // Outside Radius
	rr := g.GetRootCircleDia() * factor / 2 // Root Radius
	pr := g.Pd * factor / 2                 // Pitch Circle Radius
	ang = involuteIntersectAngle(br, pr)
	x, y = xyLocation(br, ang)
	offsetAng = math.Atan(y/x) * -1
	offsetAng += (math.Pi / (float64(g.N) / 2.0)) / -4.0
	if rr > br {
		sr = rr
	} else {
		sr = br
	}
	rinc := (or - sr) / 100
	for r = sr; r <= or; r += rinc {
		ang = involuteIntersectAngle(br, r)
		x, y = xyLocation(br, ang)
		px = append(px, int(x))
		py = append(py, int(y))
		pyi = append(pyi, int(y)*-1)
	}
	if br > rr {
		px = append([]int{int(rr)}, px...)
		py = append([]int{0}, py...)
		pyi = append([]int{0}, pyi...)
	}
	canvas.Gtransform(fmt.Sprintf("rotate(%0.4f)", offsetAng*RadToDeg))
	canvas.Polyline(px, py, style("solid"))
	canvas.Gend()
	canvas.Gtransform(fmt.Sprintf("rotate(%0.4f)", offsetAng*RadToDeg*-1.0))
	canvas.Polyline(px, pyi, style("solid"))
	canvas.Gend()
	sx, sy := rotXY(px[len(px)-1], py[len(py)-1], offsetAng)
	ex, ey := rotXY(px[len(px)-1], pyi[len(pyi)-1], offsetAng*-1.0)
	canvas.Path(fmt.Sprintf("M%d,%d A%d,%d 0 0 1 %d,%d",
		sx, sy, int(or), int(or),
		ex, ey), style("solid"))

	sx, sy = rotXY(px[0], py[0], -offsetAng)
	ex, ey = rotXY(px[0], py[0], ((2*math.Pi)/float64(g.N))+offsetAng)
	canvas.Path(fmt.Sprintf("M%d,%d A%d,%d 0 0 1 %d,%d",
		sx, sy, int(rr), int(rr),
		ex, ey), style("solid"))
}
コード例 #2
0
ファイル: plot.go プロジェクト: bernhard-hofmann/GearGen
func plotGear(cx int, cy int, rot float64, g gear.Gear, canvas *svg.SVG) {
	canvas.Gtransform(fmt.Sprintf("translate(%d, %d)", cx, cy))
	canvas.Circle(0, 0, int(g.Pd*factor/2), style("dash"))
	cntrLen := int(g.GetOutsideDia() * factor / 8)
	canvas.Line(-cntrLen, 0, cntrLen, 0, style("solid"))
	canvas.Line(0, -cntrLen, 0, cntrLen, style("solid"))
	canvas.Gtransform(fmt.Sprintf("rotate(%0.3f)", rot))
	for i := 0; i < g.N; i++ {
		canvas.Line(int((math.Cos((360/float64(g.N))*float64(i)*DegToRad) * g.GetRootCircleDia() * factor / 2)),
			int((math.Sin((360/float64(g.N))*float64(i)*DegToRad) * g.GetRootCircleDia() * factor / 2)),
			int((math.Cos((360/float64(g.N))*float64(i)*DegToRad) * g.GetOutsideDia() * factor / 2)),
			int((math.Sin((360/float64(g.N))*float64(i)*DegToRad) * g.GetOutsideDia() * factor / 2)),
			style("dash"))
		canvas.Gtransform(fmt.Sprintf("rotate(%f)", 360.0/float64(g.N)*float64(i)))
		plotInvCurve(g, canvas)
		canvas.Gend()
	}
	canvas.Gend()
	canvas.Gend()
}