how to call the x component of a vector in python

Watch
localmemelord
Badges: 15
Rep:
?
#1
Report Thread starter 1 month ago
#1
how would you write the x component of :
a = sphere(pos = vector(1,2,3)) *example
0
reply
MrSandyWilly
Badges: 18
Rep:
?
#2
Report 1 month ago
#2
(Original post by localmemelord)
how would you write the x component of :
a = sphere(pos = vector(1,2,3)) *example
That doesn't look like correct Python to me... what module is this?
0
reply
localmemelord
Badges: 15
Rep:
?
#3
Report Thread starter 1 month ago
#3
(Original post by MrSandyWilly)
That doesn't look like correct Python to me... what module is this?
vpython
0
reply
MrSandyWilly
Badges: 18
Rep:
?
#4
Report 1 month ago
#4
Isn't the x-component this:

a = sphere(pos = vector(1,2,3))
0
reply
localmemelord
Badges: 15
Rep:
?
#5
Report Thread starter 1 month ago
#5
(Original post by MrSandyWilly)
Isn't the x-component this:

a = sphere(pos = vector(1,2,3))
no i mean, what is the line of code that calls the x component of that vector
0
reply
Sinnoh
Badges: 22
Rep:
?
#6
Report 1 month ago
#6
a.pos[0]? I'm assuming sphere is a class

never heard of vpython, I'd have just used a numpy array
Last edited by Sinnoh; 1 month ago
0
reply
localmemelord
Badges: 15
Rep:
?
#7
Report Thread starter 1 month ago
#7
(Original post by Sinnoh)
a.pos[0]? I'm assuming sphere is a class

never heard of vpython, I'd have just used a numpy array
that doesnt work unfortunately, a typeerror forms:
"'vpython.cyvector.vector' object is not subscriptable"
0
reply
Sinnoh
Badges: 22
Rep:
?
#8
Report 1 month ago
#8
(Original post by localmemelord)
that doesnt work unfortunately, a typeerror forms:
"'vpython.cyvector.vector' object is not subscriptable"
ugh.

It must have its own method for calling the component then
0
reply
localmemelord
Badges: 15
Rep:
?
#9
Report Thread starter 1 month ago
#9
(Original post by Sinnoh)
ugh.

It must have its own method for calling the component then
it seems so
0
reply
just_m3
Badges: 6
Rep:
?
#10
Report 1 month ago
#10
What about print()

See the bottom of the documentation page:

https://www.glowscript.org/docs/VPyt...sualIntro.html
0
reply
localmemelord
Badges: 15
Rep:
?
#11
Report Thread starter 1 month ago
#11
(Original post by just_m3)
What about print()

See the bottom of the documentation page:

https://www.glowscript.org/docs/VPyt...sualIntro.html
wouldnt that print out all of the components instead of only the x component
0
reply
davros
  • Study Helper
Badges: 16
Rep:
?
#12
Report 1 month ago
#12
(Original post by localmemelord)
wouldnt that print out all of the components instead of only the x component
I've never used vPython, but doesn't the paragraph headed "Vectors" on that site indicate that if a is a vPython vector object then you may refer to its components as a.x, a.y, a.z etc?
1
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Have you experienced financial difficulties as a student due to Covid-19?

Yes, I have really struggled financially (20)
14.18%
I have experienced some financial difficulties (35)
24.82%
I haven't experienced any financial difficulties and things have stayed the same (61)
43.26%
I have had better financial opportunities as a result of the pandemic (21)
14.89%
I've had another experience (let us know in the thread!) (4)
2.84%

Watched Threads

View All