Python 3D Graphics LESSON 16: Modeling a 3D Analog Clock in Vpython

preview_player
Показать описание
You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:

In this video we show step-by-step instructions on how to build a 3D clock face model in Vpython. We will animate the clock in this lesson, with second, minute and hour hands..

#Python
#Lessons
#Graphics
Рекомендации по теме
Комментарии
Автор

Thank you, Paul. I really like your teaching. Thanks to you, i'm passionate about vpython.

I think it is not necessary to calibrate the clock if we choose the right rate and the right increment. Since the seconds hand completes a circular revolution in 60 seconds, the angle completed in 1 second must be 2*np.pi/60.
As rate(x) means x updates in 1 second, the increment must be (2*np.pi/60)/x.
For example, if the rate is set to 60, the angle's increment for the seconds hands must be np.pi/1800. Then, the while loop could be something like that:

t = 0
while True:
t += np.pi/1800
rate(60)
sHand.axis = vector(sHl*sin(t), sHl*cos(t), 0)
mHand.axis = vector(mHl*sin(t/60), mHl*cos(t/60), 0)
hHand.axis = vector(hHl*sin(t/720), hHl*cos(t/720), 0)

Ps1: I used here my own notation, where sHl, mHl and hHl are the lengths of the three hands.

Ps2: I just realized that sin and cos are already in vpython. We can therefore directly write sin, cos (without np).

jeas
Автор

Paul, I have a suggestion for those long lines. When declaring the objects, put each parameter on a separate line. For example:

clockFace = cylinder(axis=vector(0, 0, 1),
color=color=vector(0, 1, .8),
length=clockT
radius=clockR,
pos=vector(0, 0, -clockT/2))

This gives you the advantage of seeing all the parameters at a glance instead of having to scroll over to find it and makes it easy to add a new parameter if needed without the scrolling

stefanonicolini
Автор

May god bless you Mr. Paul. I can not believe that all the beauty we learn here is set for free. You are a real and complete legend Mr. Paul.

Octopus-
Автор

I knew you prepared these videos in advance, but did not know it was 8 MONTHS in advance haha. Most excellent prepping.

learningcode
Автор

I AM LEGEND! My second hand often jumps in 2 second steps, but otherwise my clock is great and keeps perfect time. Thanks again for these wonderful lessons, Paul.

cbrombaugh
Автор

Hello Paul. This is Mamadou from Senegal. These days I'm not lucky because I've resumed teaching at the university, and your stream coincides with my class. Thanks for your most instructive videos.

mamadoubapassioninformatique
Автор

Hi Paul, i am Legend. I made an accurate clock using the Time library and it is a wonder to behold. I didn't cheat this time (not like the last time) so I'll now go and watch the next tutorial to see how close I got to your solution to this project. Thanks, as always, for these great tutorials. 🕺🕺🕺

alfredcalleja
Автор

i was able to get it fairly accurate using threading! thank you Paul for your great instruction!

vaughntaylor
Автор

LIke the Mission Impossile reference...Yes, at 60 I guess I'm old ... No homework is impossible under the instruction of Paul M.

justmc
Автор

Great lessons Paul. I inadvertently stumbled on that adding "sleep(1)" at beginning of the while loop makes it run to correct time intervals regardless of the rate

benthompson
Автор

I got it to show quite accurate calibrated time. Will try to do the homework now in order to make it show the actual time. Thanks for your lessons. You are really great at teaching and making it look so simple.

ecassar
Автор

Thank you Sir Paul, getting more knowledge from you

edgarpanunciolobitana
Автор

I sat and watched because I didn't understand your homework but I was a legend in the other homeworks

idkwhatiamdoing
Автор

Once you highlight a word you can command & d to select all of the same words one at a time down the program. Then edit all at once. Very nice shortcut. Double chest bump

Bubby
Автор

Hay Paul, I love these lesson vary much. But when are you going to make more Arduino lessons

deepstate
Автор

I am legend. That was fun fiddling with the parameters until I could get it to work just like a real clock. As practice, I also got the clock face to change color like the color orb we did.

starRunnerX
Автор

I managed to do the homework. Did two versions. For one I used he same code to get a reasonably calibrated time, but I added code whereby the resultant error is corrected every second that passes. The other one display the actual time every time it goes through the while loop. Still have no idea what your solution was as I haven't seen the next video as yet. So, it is possible that you came up with a completely different code to mine, but I'm glad that I came up with two solutions.

ecassar
Автор

I calibrated my clock using the inc/rate approach to be under a second slow. Using the time.localtime function as my starting position for the axes of the clock hands my clock performed well but 'drifted' and after an hour it was about 45 secs slow.

Next attempt was to replace the inc/rate method of incrementing the angles of the hands with a simple second counter and sleep(1) delay in the while loop. The second hand 'ticked' over for each iteration of the while loop and the minute hand ticked over after 60 seconds. The hour hand moves slowly as a proportion of the position of the minute hand. All good except there is still a time drift using this method. Every 300 seconds I retrieved the system time and compared to myTime and my clock would lose about 1 second every 5 minutes. Looks like the overhead for calculating the axis values in the while loop is not inconsequential.

martinjones
Автор

How many more lessons is there left I hope there is a lot more to com.

juliethies
Автор

I created the second hand to be the primary hand and then modified the minute hand to operate off the second hand parameters and of course the hour hand was already operating off the minute hand parameters. As stated in my last comment, the closest I could get the second hand to clock accurate was .003 in the "secondInc" which ended up being about 58.5 seconds per rotation.

wayneswan