Python 3D Graphics Tutorial 4: Understanding 3D Graphic Parameters

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 understand and use parameters in 3D design and modeling in vpython, (visual python), and how to bring your models to life. I do not assume you are an expert, so these lessons are designed for complete beginners.
#Python
#Lessons
#Programming
Рекомендации по теме
Комментарии
Автор

I came here from Arduino videos and I cannot express how grateful I am for everything you're doing Mr. Paul McWhorter. You produce high quality content that I couldn't find anywhere else. Thank you!

dryym
Автор

I am really excited and blessed meeting you Mr. Paul McWhorter

zpzkbiy
Автор

Had fun with the kids yesterday building a robot (with box) in the room and having the sphere turn around it. Since teaching the kids is the reason I grind these lessons, I want to thank you for it all. Only the beginning, can't wait for us to build mini robots and play with the arduino eventually. Have a great day sir! 💥☕

maku
Автор

I am Legend. I just followed your 1D animation. Then just extended to 2D like carrom Board. Then finally I did 3D. Just with two extra "if" statements and eight new variables. All thanks to you Paul.
Great Tutorials. I really appreciate your effort and being consistent.

soundarrajankannan
Автор

Already made an appointment on my calendar, not that I would need one because I am subscribed and part of the notification squad.

Can't wait till Paul does a Data Analysis Python tutorial, solely on libraries like scipy, numpy, pandas :)

Will become a Patreon supporter when I get my first paycheck!

hanshearth
Автор

Hi Paul, "I am Legend"! I got the homework right first time and it's a work of art. I removed the right hand wall so I could get a bird's eye view of the ball bouncing off all the internal walls (even though the front and right hand walls were not there. Thanks again for a great tutorial.

alfredcalleja
Автор

Great lesson. Instead of adding the extra variables, I just changed the "if" statement to: "if or

kevinflanigan
Автор

I AM LEGEND!! I somehow managed to complete this with only one error, switching a < and > for the if statement for the z direction. This was so satisfying to complete and watch, thanks so much for the great lesson Mr. McWhorter!!

MichaelDeCiantis-ywqy
Автор

That last homework assignment was a good challenge. I learned a lot. Ready for more. :)

colepdx
Автор

if
if
I did like this for my assignment, it was not perfect bounce as you did in this tutorial. Love the lessons a lot.

aungphyokyaw
Автор

Also doing your AI course where we installed multiple interpreters. Couldn't work out for a moment why my vpython wouldn't run. Then penny dropped - was still in the venv for python 3.6.

neilausten
Автор

I am LEGEND.. Here is my solution to homework assignment given in Lesson 3 ..
I created a new variable called 'ballTravel' .... ballTravel = (roomWidth / 2) - (wallThickness / 2) - (mRadius).
Used it in the 'while' loop. . Looks good here. Thanks again Paul for a great lesson

mRadius = 0.5
wallThickness = 0.1
roomWidth = 15
roomDepth = 5
roomHeight = 10

floor = box(
pos=vector(0, -roomHeight / 2, 0),
color=color.white,
size=vector(roomWidth, wallThickness, roomDepth),
)
ceiling = box(
pos=vector(0, roomHeight / 2, 0),
color=color.white,
size=vector(roomWidth, wallThickness, roomDepth),
)
rSide = box(
pos=vector(roomWidth / 2, 0, 0),
color=color.white,
size=vector(wallThickness, roomHeight, roomDepth),
)
lSide = box(
pos=vector(-roomWidth / 2, 0, 0),
color=color.white,
size=vector(wallThickness, roomHeight, roomDepth),
)
back = box(
pos=vector(0, 0, -roomDepth / 2),
color=color.white,
size=vector(roomWidth, roomHeight, wallThickness),
)
marble = sphere(color=color.red, radius=mRadius)
deltaX = 0.1
xPos = 0
ballTravel = (roomWidth / 2) - (wallThickness / 2) - (mRadius)

while True:
rate(30)
xPos = xPos + deltaX
if xPos > ballTravel or xPos < -ballTravel:
deltaX = deltaX * (-1)
marble.pos = vector(xPos, 0, 0)

justmc
Автор

As a professional cad designer this is a piece of cake, so sure I'm legend.
I did put in a 'glass' in the front so we can see the ball bouncing and yet the box is closed.

from vpython import *
from time import *
mRadius=1
wallThickness=.2
roomWidth=15
roomDepth=20
roomHeight=5.5
floor=box(pos=vector(0, -roomHeight/2, 0), color=color.red, size=vector(roomWidth, wallThickness, roomDepth))
ceiling=box(pos=vector(0, roomHeight/2, 0), color=color.red, size=vector(roomWidth, wallThickness, roomDepth))
leftwall=box(pos=vector(-roomWidth/2, 0, 0), color=color.red, size=vector(wallThickness, roomHeight, roomDepth))
rightwall=box(pos=vector(roomWidth/2, 0, 0), color=color.red, size=vector(wallThickness, roomHeight, roomDepth))
backwall=box(pos=vector(0, 0, -roomDepth/2), color=color.red, size=vector(roomWidth, roomHeight, wallThickness))
frontwall=box(pos=vector(0, 0, roomDepth/2), color=color.white, opacity=0.15, size=vector(roomWidth, roomHeight, wallThickness))
marble=sphere(radius=mRadius, color=color.blue)
deltaX=.1
deltaY=.1
deltaZ=.1
xPos=0
yPos=0
zPos=0
while True:
rate(40)
xPos=xPos+deltaX
if or :
deltaX=deltaX*-1
yPos=yPos+deltaY
if or :
deltaY=deltaY*-1
zPos=zPos+deltaZ
if or :
deltaZ=deltaZ*-1
marble.pos=vector(xPos, yPos, zPos)

wendygrant
Автор

First one was excellent. I saw the '3D Graphics..' in title and was like; _Already?..._ lol.
Best wishes and keep up the awesome.

johnhansen
Автор

Thank you Paul, it was fun but no secret word at end
I solve it with modifiying 1 line :
if or

ToniHayek
Автор

I completely get the addition of the two variables for 'perfect bouncing' in one dimension, however for all three, I found it simpler to include more of the original parameters in the conditionals (after all the new parameters were based on the existing ones...:
for i in range(0, 3): # shifts the ball incrementally
pos[i] = pos[i] + delta[i] # in all three dimensions
if (pos[0] >= (width/2 - rad - thickness/2) or pos[0] <= -(width/2 - rad - thickness/2)):
delta[0] = delta[0] * (-1) # bouncing off the left and right walls
if (pos[1] >= (height/2 - rad - thickness/2) or pos[1] <= -(height/2 - rad - thickness/2)):
delta[1] = delta[1] * (-1) # bouncing off the top and bottom walls
if (pos[2] >= (depth/2 - rad - thickness/2) or pos[2] <= -(depth/2 - rad - thickness/2)):
delta[2] = delta[2] * (-1) # bouncing off the back and 'front' wall (we haven't rendered the front wall)
# so we can see what's happening
I also used an array for position and delta to keep things a bit neater for my own ease of reference, but that's just personal preference :-)🙂

I am also legend by the way 🙂

JackVersey
Автор

You know -- oddly enough -- I found the visual graphics of this relatively easier to learn than the syntax stuff. Maybe cause you can see visually the logic unfold for what you are programming.
Thank you! No scholastic background in computer programming -- did STEM for Molecular Biology.
Greatly appreciate these lessons!

BadReliginFan
Автор

Commenting during the intro to help the youtube algorithm out :)

To simplify the quotes in my IF statement. I created a new VAR



Then my if statement just got adjusted to:

if(xPos>roomEdge or xPos<-roomEdge):

NOS
Автор

Hi Mr Paul, thank you very much.

Best regards from Algeria.

RachidRachid-mngm
Автор

Since mradius is a parameter, you can also use "if xpos > (roomwidth/2)-mradius or xpos < (-roomwidth/2)+mradius"

lokey