Page 1 of 1

## 2 Replies - 193 Views - Last Post: 07 October 2012 - 08:36 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=294571&amp;s=da21ebc217d5336176b11576a558ea5f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 saminator910

Reputation: 0
• Posts: 2
• Joined: 06-October 12

Posted 06 October 2012 - 08:29 PM

I created a fairly simple program to create a 3d vector field, I want to know how to make it so that you can input equations for x,y,z instead of editing the code each time.

```from visual import *
curve(pos=[(-15,-15,15),(-15,15,15),(15,15,15),(15,-15,15),(-15,-15,15)])
curve(pos=[(-15,-15,-15),(-15,15,-15),(15,15,-15),(15,-15,-15),(-15,-15,-15)])
curve(pos=[(15,-15,15),(15,-15,-15)])
curve(pos=[(-15,-15,15),(-15,-15,-15)])
curve(pos=[(-15,15,15),(-15,15,-15)])
curve(pos=[(15,15,15),(15,15,-15)])
points(pos=[(0,0,0)])
label(pos=(15,0,0), text = 'x+')
label(pos=(0,0,15), text = 'z+')
label(pos=(0,15,0), text = 'y+')
label(pos=(0,0,0), text = 'O')

x = -10
y = -10
z = -10

while  z <= 10:

a = .5*x   #the area of interest, this is where you set a,b,c equal to a equations for x, y, z
b = .5*y
c = .5*z

d = arrow(pos = (x,y,z), axis = (a,b,c))

if x < 10:
x = x+5

elif y < 10:
y = y+5
x = -10

elif z <= 10:
z = z+5
y = -10
x = -10

```

So I need to set the individual variables a,b,c equal to different equations of x,y,z. How am I supposed to do this without editing the code each time, if I can assign a some type of variable to these equations, I can easily create an input.I have no idea. I am new to python BTW, picked it up to create a program for vector fields.

Is This A Good Question/Topic? 0

### #2 baavgai

• Dreaming Coder

Reputation: 4949
• Posts: 11,356
• Joined: 16-October 07

Posted 07 October 2012 - 04:49 AM

I'm not really following the question. I did have fun playing with this, though.

First, function. Always use functions:
```from visual import *

def drawField():
curve(pos=[(-15,-15,15),(-15,15,15),(15,15,15),(15,-15,15),(-15,-15,15)])
curve(pos=[(-15,-15,-15),(-15,15,-15),(15,15,-15),(15,-15,-15),(-15,-15,-15)])
curve(pos=[(15,-15,15),(15,-15,-15)])
curve(pos=[(-15,-15,15),(-15,-15,-15)])
curve(pos=[(-15,15,15),(-15,15,-15)])
curve(pos=[(15,15,15),(15,15,-15)])
points(pos=[(0,0,0)])
label(pos=(15,0,0), text = 'x+')
label(pos=(0,0,15), text = 'z+')
label(pos=(0,15,0), text = 'y+')
label(pos=(0,0,0), text = 'O')

def drawArrows():
x, y, z = -10, -10, -10

while  z <= 10:
(a,b,c) = (0.5*x, 0.5*y, 0.5*z)
arrow(pos = (x,y,z), axis = (a,b,c))

if x < 10:
x = x+5
elif y < 10:
y = y+5
x = -10
elif z <= 10:
z = z+5
y = -10
x = -10

drawField()
drawArrows()

```

It took me a moment to figure out what kind of pattern drawArrows as aiming for. Then figured out it was this:
```def drawArrows():
for z in range(-10, 10+1, 5):
for y in range(-10, 10+1, 5):
for x in range(-10, 10+1, 5):
(a,b,c) = (0.5*x, 0.5*y, 0.5*z)
arrow(pos = (x,y,z), axis = (a,b,c))

```

If the question is how to express that in terms of a,b,c rather than x,y,z, you'd simply reverse it:
```def drawArrows():
steps = [ i*0.5 for i in range(-10, 10+1, 5) ]
for c in steps:
for b in steps:
for a in steps:
(x,y,z) = 2.0*a, 2.0*b, 2.0*c
arrow(pos = (x,y,z), axis = (a,b,c))

```

Perhaps if you had an example of what values you change and why?

This post has been edited by baavgai: 07 October 2012 - 04:50 AM

### #3 saminator910

Reputation: 0
• Posts: 2
• Joined: 06-October 12

Posted 07 October 2012 - 08:36 AM

Sure, I make equations in terms of x,y,z for a. they change the vector field, for example I may change it to this

```    a = .25*z
b = .25*y
c = .25*z

```

or this

```    a = .25*y
b = .25*-2
c = .25*x

```

or this

```    a = .25*x
b = .25*y
c = .25*z

```

I want to be able to change the equations on the right side without going in an editing it each time, I will create an input, but I have no idea how to set those equations equal to variables, or inputs.