func NumSharpTurns(points [][2]float64) int {
	arrLens := len(points) - 2
	// dists := make([]float64, arrLens)
	angles := make([]float64, arrLens)

	for idx := 0; idx < arrLens; idx++ {
		var p1, p2, p3, v1, v2 mgl64.Vec2

		p1 = points[idx]
		p2 = points[idx+1]
		p3 = points[idx+2]

		v1 = p2.Sub(p1)
		v2 = p3.Sub(p2)

		// dists[idx] := v1.Len()
		angles[idx] = AngleBetween(v1, v2) // (radians)
	}

	const maxAngleChange = .4 * math.Pi
	const maxDistChange = 4

	numSharpTurns := 0 // sharp turn is whenn the angles add up to maxAngleChange for 4 consecutive points

	for idx := 0; idx < arrLens; idx++ {
		dAngle := 0.0
		for count := 0; count < maxDistChange && idx < arrLens; count++ {
			dAngle += angles[idx]
			idx++
		}

		if dAngle > maxAngleChange {
			numSharpTurns++
		}
	}

	return numSharpTurns
}
Beispiel #2
0
func (o *OpenGlStream) SetPosWithExpandedPosition(pos mgl64.Vec2, x, y uint32) {
	o.pos = pos.Add(mgl64.Vec2{float64(x * fontWidth), float64(y * fontHeight)})
	o.lineStartX = pos[0]
	o.advance = x
}
Beispiel #3
0
func DrawBox(pos, size mgl64.Vec2, borderColor, backgroundColor mgl64.Vec3) {
	DrawBorderlessBox(pos.Add(mgl64.Vec2{-1, -1}), size.Add(mgl64.Vec2{2, 2}), borderColor)
	DrawBorderlessBox(pos, size, backgroundColor)
}
Beispiel #4
0
func DrawBorderlessBox(pos, size mgl64.Vec2, backgroundColor mgl64.Vec3) {
	gl.Color3dv(&backgroundColor[0])
	gl.Rectd(float64(pos[0]), float64(pos[1]), float64(pos.Add(size)[0]), float64(pos.Add(size)[1]))
}
Beispiel #5
0
func (w *Widget) ParentToLocal(ParentPosition mgl64.Vec2) (LocalPosition mgl64.Vec2) {
	return ParentPosition.Sub(w.pos)
}
Beispiel #6
0
func AngleBetween(v1 mgl64.Vec2, v2 mgl64.Vec2) float64 {
	return math.Acos(v1.Dot(v2) / (v1.Len() * v2.Len()))
}
Beispiel #7
0
func catmullRom(p1, p2, p3, p4 mgl64.Vec2, u float64) mgl64.Vec2 {
	var B mgl64.Mat4

	B.Set(0, 0, 1)
	B.Set(0, 1, -3)
	B.Set(0, 2, 3)
	B.Set(0, 3, -1)
	B.Set(1, 0, 4)
	B.Set(1, 1, 0)
	B.Set(1, 2, -6)
	B.Set(1, 3, 3)
	B.Set(2, 0, 1)
	B.Set(2, 1, 3)
	B.Set(2, 2, 3)
	B.Set(2, 3, -3)
	B.Set(3, 0, 0)
	B.Set(3, 1, 0)
	B.Set(3, 2, 0)
	B.Set(3, 3, 1)

	B = B.Mul(1.0 / 6.0)

	var pMat mgl64.Mat2x4

	pMat.Set(0, 0, p1.X())
	pMat.Set(1, 0, p1.Y())
	pMat.Set(0, 1, p2.X())
	pMat.Set(1, 1, p2.Y())
	pMat.Set(0, 2, p3.X())
	pMat.Set(1, 2, p3.Y())
	pMat.Set(0, 3, p4.X())
	pMat.Set(1, 3, p4.Y())

	return pMat.Mul4(B).Mul4x1(mgl64.Vec4{0, 1, 2 * u, 2 * u * u})
}