HELP

89 views
Skip to first unread message

Marcus Chitura

unread,
Jun 3, 2021, 2:33:24 PM6/3/21
to Glowscript Users
can anyone help me with this code , doing an assignment and it is totally killing me

GlowScript 3.0 VPython
Sun=sphere(pos=vector(0,0,0),radius=7e9)
Mercury=sphere(pos=vector(5.8e10,0,0),radius=4e9)
Venus=sphere(pos=vector(1.1e11,0,0),radius=6e9)
Earth=sphere(pos=vector(1.5e11,0,0),radius=6.4e9)
Probe=sphere(pos=vector(2e11,0,0),radius=1.2e9)
a1=arrow(pos=Earth.pos,axis=vector(Mercury.pos-Earth.pos),color=color.white)
a2=arrow(pos=Earth.pos,axis=vector(Probe.pos-Earth.pos),color=color.blue)
deltar = vector(1e9,0,0).rotate(45)
step=0
while step<100:
   step=step+1
   Mercury.pos = Mercury.pos+deltar
   rate(20)
  

The code I have so far I have 2last objectives 
  • Make the arrow a1 point from the Earth to Mercury at all times, while Mercury moves. Insert an appropriate statement into the while loop (indented) to update the arrow a1 so that its tail remains on the Earth but its tip is always on Mercury. Don’t create any new arrows; just update attributes of your existing arrow a1. Your Mercury has been moving to the right, in the +x-direction.

  • Finally, change deltar in such a way that Mercury moves northeast, that is, up and to the right at a 45 degree angle to the horizontal. The tip of the arrow pointing from the Earth to Mercury must remain on Mercury during the motion.

  • HELP IF YOU CAN



11 Irishjs

unread,
Jun 4, 2021, 4:47:12 AM6/4/21
to glowscri...@googlegroups.com
For your second-to-last objective, couldn't you just add a statement that updates the axis of a1 to be equal to the Mercury position - the Earth's position? About the tail remaining on Earth, the arrow already does this because you created it with its tail on Earth and never told it otherwise.
You could change the while loop to look like this:

while step<100:
   step=step+1
   Mercury.pos = Mercury.pos+deltar
   a1.axis = vector(Mercury.pos-Earth.pos)
   rate(20)


For your last objective, you need to convert your angle from radians to degrees. This is because the default unit is radians and you are wanting 45 degrees, not radians. The conversion rate is (2*pi/360). This will give you an angle of 1  degree. If you want 45 degrees, you would need to divide by 8 instead of 360, because 45 is one-eighth of a complete circle. In short, you could change the deltar line to this:

deltar = vector(1e9,0,0).rotate(2*pi/8)

Patrick

--

---
You received this message because you are subscribed to the Google Groups "Glowscript Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glowscript-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glowscript-users/205d236a-52de-4849-a666-3cecd37abb2cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages