Day 171: Sierpinski Triangle Troubleshooting

Imag1037

AP students are writing a VPython program to generate the Sierpinski Triangle using the rules of the chaos game. Can you find the error in this group’s code?

Advertisements

About Frank Noschese

HS Physics Teacher constantly questioning my teaching.

One response to “Day 171: Sierpinski Triangle Troubleshooting”

  1. chris_harrow says :

    The -ball.pos.x is a nice red herring. The negative isn’t needed and actually horizontally flips the triangle. Because p1, p2, and p3 define a horizontally symmetric triangle, this "error" is visually undetectable. I believe the error is in the If n=1 subroutine. The ball.pos.y redefinition should be added, not subtracted. By using "-p1.pos.y", this essentially redefines p1 as (0,-sqrt(3)/2,0). You get another Sierpinski triangle, just not where it was expected. From my perspective, the easiest way to understand this is that the mean of any two points is always the midpoint of the given points. All of the addends should be positive and added.I don’t know VPython, but I’m wondering if the code could have been simplified a bit. Would the following work?If n==1: ball.pos=(ball.pos+p1.pos)/2If n==2: ball.pos=(ball.pos+p2.pos)/2If n==3: ball.pos=(ball.pos+p3.pos)/2That is, can the position recomputations be done on the entire vectors, or must they be done on the individual vector components?Fun problem and fun project. Thanks for sharing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: