0

I am trying to draw an arc with a constant height between 2 vertices. What I have now creates the arc, but I am wondering how I can rotate it to connect with the second vertex. Is there some alternative way I should be drawing this?

vertex1Pos = vertex1.pos
vertex2Pos = vertex2.pos #positions of 2 verticies
distance = vertex1.distance(vertex2) #distance between verticies
arcRect = [vertex1Pos.x,vertex1.pos.y - c.ARC_HEIGHT/2, distance, c.ARC_HEIGHT] #left, top, width, height of arc

while 1:
    screen.fill((200,200,200)) #gray background
    graphManager.drawGraph(screen) #draw vertices (1 & 2 in this instance)
    py.draw.arc(screen, (0,255,0), arcRect, 0, math.pi, 2)
    py.draw.rect(screen, (100,100,100), arcRect,  2)
    py.display.update()

Current output

martineau
  • 119,623
  • 25
  • 170
  • 301
AuFries
  • 23
  • 5
  • Rotating an arc would involve adding the amount of rotation to its start and stop angles. – martineau Jul 04 '22 at 23:12
  • @martineau sure, but how would I position the arc then? The way pygame works is by taking the left, top, width, and height to draw the arc (the gray box is the arc bounds). I want it always to be 0 to pi with a set height and variable width. – AuFries Jul 04 '22 at 23:28
  • Good point. AFAIK, [`pygame.draw.arc()`](https://www.pygame.org/docs/ref/draw.html#pygame.draw.arc) can't draw rotated non-circular arcs because of the way arcs are specified to it — there's no way to give it a properly rotated `rect` argument. To do what's need will require writing your own arc-drawing function. – martineau Jul 05 '22 at 00:02
  • You may find some ideas here: [drawing a diagonal ellipse with pygame](https://stackoverflow.com/questions/23281952/drawing-a-diagonal-ellipse-with-pygame/65774382#65774382) and here: [How to draw a rotated ellipse using Pygame?](https://stackoverflow.com/questions/65767785/how-to-draw-a-rotated-ellipse-using-pygame/65769408#65769408) – Rabbid76 Jul 05 '22 at 05:00

0 Answers0