-1

I'd like to draw an equilateral triangle in python by hard coding, I don't want to use specific features. The code I wrote is as follows:

#Geometry of the system

#drawing triangles
#Triangle ABC
#A
#B
#C


# x axis values
a = [1, 41, 81, 1]
# y axis values
b = [1, 70,  1, 1]

#to fix the aspect ratio:

#ax = plt.gca()
#ax.set_aspect(1)

plt.plot(a,b,'-g')
plt.xlabel("$y/\u0394x$", fontsize=12)
plt.ylabel("$z/\u0394x$", fontsize=12)
plt.ylim(0,85)
plt.xlim(0,85)

plt.xticks(size = 12)
plt.yticks(size = 12)

plt.axis('scaled')
#ax.set_aspect('equal')
#plt.figure(figsize=(10,10))

# function to show the plot
plt.show()


Now, I believe that my calculation and the correct coordination of each corner of the triangle are accurate. However, when I get the figure, the triangle does not look equilateral. Could you please help me to solve this problem? Do I need to fix the aspect ratio and how can I fix the aspect ratio?

Also, the figure is attached for your reference. enter image description here

Thank you!

saba
  • 1
  • 2
  • 1
    That looks like an equilateral triangle to me. – 0x5453 Oct 11 '22 at 13:12
  • What makes you think it is not equilateral? – blackbrandt Oct 11 '22 at 13:16
  • 1
    Ok, it is [definitely](https://i.imgur.com/mFnIFmc.png) equilateral. I'm voting to close as not reproducable. – 0x5453 Oct 11 '22 at 13:20
  • @0x5453 That's a neat figure! How did you generate it? – Ben Grossmann Oct 11 '22 at 13:26
  • @saba Please clarify what you mean when you say "the triangle does not look equilateral" – Ben Grossmann Oct 11 '22 at 13:27
  • 1
    It is notable, perhaps, that there are no integer coordinates that lead to a triangle that is *exactly* equilateral. However, this triangle is close enough that there should be no perceptible difference: the base is 0.3% longer than either of the other two sides, which have the same length. – Ben Grossmann Oct 11 '22 at 13:30
  • @BenGrossmann By hand, basically. Open image in [GIMP](https://www.gimp.org/), duplicate layer twice, rotate layers by +-120 degrees, decrease opacity of top layers. – 0x5453 Oct 11 '22 at 13:34
  • https://stackoverflow.com/questions/44132810/matplotlib-draw-triangle-with-given-sides-from-input – A. Herlas Oct 11 '22 at 13:36
  • @0x5453 Got it, thanks! I'll have to start using GIMP one of these days :) – Ben Grossmann Oct 11 '22 at 13:42

1 Answers1

4

There is nothing wrong with your aspect ratio and it does look like an equilateral triangle from a human eye.

That being said, mathematically the points you've chosen do not form 3 equal sides - if you apply the Euclidian distance formula between them, the base is very slightly longer than the other two.

I doubt you'd ever manage to find nice integer points to hard-code, because the height of an equilateral triangle is sqrt(3) * side/ 2, which is a non-terminating decimal. You can use (41, 70.282) to get closer to a perfect match, but I doubt it'll be a huge improvement for the human eye.

shriakhilc
  • 2,922
  • 2
  • 12
  • 17
  • Indeed, it is [impossible to find integer coordinates](https://math.stackexchange.com/q/105330/81360) of corners of an equilateral triangle – Ben Grossmann Oct 11 '22 at 13:43