# 3D Vector "End Point" Calculation for procedural Vector Graphics

Alright, So I need some help with some Vector Math.

I've developing some game Engines that have Procedural Fractal Generation for Some Graphics, such as using Lindenmayer Systems for generating Trees and Plants. L-Systems, are drawn by using Turtle Graphics, which is a form of Vector graphics.

I first created a system to draw in 2D Graphics, which works perfectly fine. But now I want to make a 3D equivalent, and I’ve run into an issue.

For my 2D Version, I created a Method for quickly determining the “End Point” of a Vector-like movement. Given a starting point (X, Y), a direction (between 0 and 360 degrees), and a distance, the end point is calculated by these formulas:

newX = startX + distance * Sin((PI * direction) / 180)

newY = startY + distance * Cos((PI * direction) / 180)

Now I need something Similarly Equivalent for performing this Calculation in 3D, But I haven’t been able to Google anything that could show me how to do this.

I'm flexible enough to get whatever required information is needed for this method calculation, in any reasonable form (Vector3, Quaternion, ect).

To summarize: Given a starting point/vector position in 3D space (X, Y, Z), a Direction in 3D space (Vector3, Quaternion, ect), and a Distance, I need to find the “End Point” in 3D Space.

Thank you for your time and help.

An equivalent in 3D is quite simple, without using quaternions or anything of the sort (since it's really not the case - you need to specify a convention, not to perform computations). Hence, spherical coordinates:

 NewPoint.X = Start.X + distance * Cos(longitudeAngle) * Cos(latitudeAngle);
NewPoint.Y = Start.Y + distance * Sin(longitudeAngle) * Cos(latitudeAngle);
NewPoint.Z = Start.Z + distance * Sin(latitudeAngle);


where longitudeAngle is between (-180 and 180) degrees or (-pi, pi) rads and the latitudeAngle is between (-90,90) degrees or (-pi/2, pi/2) rads.

Alternatively, take a look at some astronomical coordinate systems. They provide a fairly more similar approach to what you did to construct your fractal shapes by supplying a so called local direction via an angle (improperly called direction, let's call it heading or something..). This way, you can do some interesting things with L-Systems (even generate some weird random ones via any production rule you set..).

• Thanks for pointing me towards Spherical Coordinate System. This seems to be what I was looking for! Jul 9 '12 at 17:32
Vector3 endPoint = position + distance * direction;


Implying that direction is a normalized 3D vector.

• While I accepted the other post as the answer, I believe that your answer can also be useful in certain situations. Jul 9 '12 at 17:37