Equation of a Line in 3d Space


heres a question for the more mathematically minded of us…

i want to work out the equation of a line in 3d space ( i think ), if you imagine a spheres vertexes moving away from the center of the sphere along with music. for example bass would move the vertices along the equator out from the spheres center and treble would move the vertices at the polar caps away from the center.

so say i have an input of 6 for bass, i get the xyz of the centre of the sphere [0,0,0] and i get the xyz of the vertice i want to move say [4,4,2] i draw an imaginary line through these points. once i have this imaginary line i want to be able to move my vertex along it 6 points and get that point in spaces xyz, so i can use setXYZ.

if anyone understands what im on about and knows how to do it or can point me in the direction of a math resource that thicko artists can understand that would be great!


I think it is pretty simple: if you want a point to be 2x further from [0,0,0] you just multiply the its coordinates by 2.

So to place [4,4,2] 6x further from the center of your sphere, place it at [24,24,12].

thanks laurens, its always the simplest route thats best!! i was looking into trigonometry and stuff ha ha!! the only thing with this is that my input has to be 1+ anything below send the vertices inwards…

oh yeh also how would i go about doing this with a moving sphere i.e. if the centre pont was not 0,0,0 do i minus the spheres current xyz before multipying. phew im tired… :smiley:

thanks will

In Blender your object (the sphere) has a coordinate that is used to place it in the scene. When you move the sphere about, this coordinate changes.
The vertices of your sphere have a different coordinate system, relative to the center of your sphere. You can change the coordinates of those vertices when you go into “edit mode”. After you leave edit mode you can move the sphere around, but the vertices remain in the same position relative to eachother.

The bottom line is: you don’t need to do anything special when the sphere is moving.

I pretty much think those guys have given you the help you want, but you may still find this interesting if not useful.

I once had to write a script (Not in Blender) to draw a three dimensional sphere by calculating were to put all the verticies. To do this I used SINE and COSINE. I am not sure how to do it in Python, but here is how I did it.

To make a 2D circle, Sin and Cosine work something like this:

(This may be incorrect, I’m doing it from memory and I have a memory like a … whatever it’s called)

X = Sin(Angle) * Radius + Xposition_of_circle
Y = Cos(Angle) * Radius + Yposition_of_circle

So I just looped the angle 0-360 (I may have had to enter Radians, 0 to Pi * 2) and plotted the points.

To make it 3D, I looped that but changed the radius of the circle drawn with Sin, and changed the Z value with Sin.

I can dig out the old code if your interested.

Hope I helped, if not that was fun to type up anyways - lol


hi pixel8or,
yeh that script would be great to see, i could see it coming in useful in a project im working towards,


Cool, glad to help. Hope you can use this information. Your project sound very interesting. If you ever finish, I hope to be able to see it :slight_smile:

Fisrt thing to tell you is that I did not do this code in Blender or Python, but the same idea should work so look at the concept rather than the syntax. Also, you might want to find out if you can use SIN and COS in Python, because I haven’t a clue.

When I wrote this I was trying to be able to rotate a camera so that it looked at certain points of a 3D sphere (Invisable). This was because I couldn’t tell the camera what angle to look at, just x,y,z points to look at.

This same method could be used to draw lines from the center of the circle outward, if that’s what you’re looking for.

These are some variables I used: (again, this is not Python so please excuse)

float angleH;
float angleV;

float camPosX;
float camPosY;
float camPosZ;

float camLookX;
float camLookY;
float camLookZ;

To make it work for you, I would change camPosX to LineStartX or StartX or something like that. Same with Y and Z. Also I would change camLookX, Y, Z to EndX, Y, Z too.

float angleH;
float angleV;

float startX;
float startY;
float startZ;

float endX;
float endY;
float endZ;

angleH is the Horizontal angle my camera looked. (Left, right) and angleV was my verticle angle. (Up, down)

You want to make a loop that plots each point, so how you decide to get the angles is up to you. (It would depend in the project your doing)

  startX = 0;
  startY = 0;
  startZ = 0;

  endX = sin(angleH) * cos(angleV);
  endY = sin(angleV);
  endZ = cos(angleH) * cos(angleV);

So thats the formula pattern your going to want to use to get your line points. In Python it might want the angle to be in Degrees or it might want to be Radians, I don’t know.

The startX-Y-Z are your center of the sphere.

To get a higher resolution circle, plot more verticies by using more close-together angles.

I hope this helps because I’m not very good at explaining things XD
Have fun and let me know what happens.


thanks pixel8or, i dont have my laptop with me now but ill try this out over christmas and get back to you if i get it working

will :slight_smile:

Sounds great, I hope it works. :smiley: