Skip to content

Instantly share code, notes, and snippets.

@smeschke
Created January 18, 2022 05:13
Show Gist options
  • Save smeschke/a851dc7c34adc0f830aa51da602af508 to your computer and use it in GitHub Desktop.
Save smeschke/a851dc7c34adc0f830aa51da602af508 to your computer and use it in GitHub Desktop.
belt_length
import cv2
import numpy as np
import math
imgSize = 600,600, 3
coreCenter = 300,300
coreSize = 50
beltThickness = .045
beltLength = 5025
segmentStart = coreCenter[0], coreCenter[1] + coreSize
distanceFromCore = coreSize
measuredDistance = 0
img = np.zeros((imgSize), np.uint8)
cv2.circle(img, coreCenter, coreSize, (123,123,123), -1)
def distance(a,b):
return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)
for i in range(beltLength):
angle = i / 100.0
segmentEndX = math.sin(angle) * distanceFromCore + coreCenter[0]
segmentEndY = math.cos(angle) * distanceFromCore + coreCenter[1]
segmentEnd = tuple(np.array((segmentEndX, segmentEndY), int))
cv2.line(img, segmentStart, segmentEnd, (255,255,255), 1)
measuredDistance += distance(segmentStart, segmentEnd)
distanceFromCore += beltThickness
segmentStart = segmentEnd
print(measuredDistance)
cv2.imshow('img', img)
cv2.imwrite('/home/stephen/Desktop/belt.png', img)
cv2.waitKey()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment