Skip to content

FilledTriangle stretches too far horizontally #9

Description

@timboldt

I was using a FilledTriangle to draw the hands on a clock, and I noticed that the triangle for the minute hand goes outside the boundaries of the clock near the 3 o'clock and 9 o'clock positions.

Assuming there is nothing wrong with math.Sincos(), I can only assume that something is not quite right with FilledTriangle().

My logic looks something like this:

	const (
		hourRadius       = 55
		minuteRadius     = 95
		hourWidth        = 6
		minuteWidth      = 5
	)

	// Draw the clock hands.
	minuteAngle := float64(t.Minute()) / 60 * 2 * math.Pi
	mx, my := math.Sincos(minuteAngle)
	hourAngle := float64(t.Hour()*60+t.Minute()) / 60 / 12 * 2 * math.Pi
	hx, hy := math.Sincos(hourAngle)
	tinydraw.Triangle(
		display,
		x-int16(hourWidth*hy), y-int16(hourWidth*hx),
		x+int16(hourWidth*hy), y+int16(hourWidth*hx),
		x+int16(hourRadius*hx), y-int16(hourRadius*hy),
		black)
	tinydraw.FilledTriangle(
		display,
		x-int16(minuteWidth*my), y-int16(minuteWidth*mx),
		x+int16(minuteWidth*my), y+int16(minuteWidth*mx),
		x+int16(minuteRadius*mx), y-int16(minuteRadius*my),
		black)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions