Create Sine Mesh
Python code to create a sine wave mesh in Blender:
import math
import Blender
from Blender import NMesh
x = -1 * math.pi
mesh = NMesh.GetRaw()
vNew = NMesh.Vert( x, math.sin( x ), 0 )
mesh.verts.append( vNew )
while x < math.pi:
x += 0.1
vOld = vNew
vNew = NMesh.Vert( x, math.sin( x ), 0 )
mesh.verts.append( vNew )
mesh.addEdge( vOld, vNew )
NMesh.PutRaw( mesh, "SineWave", 1 )
Blender.Redraw()
The code's explanation is at: http://davidjarvis.ca/blender/tutorial-04.shtml
Algorithm to Plot Edges
Drawing one line segment is the same as drawing three, so the problem can be restated as:
How do you draw an arc on a sphere,
given two end points?
In other words, draw an arc between the following two points on a sphere:
- P1 = (x1, y1, z1)
- P2 = (x2, y2, z2)
Solve this by plotting many mid-points along the arc P1P2 as follows:
- Calculate the radius of the sphere:
R = sqrt( x12 + y12 + z12 )
- Calculate the mid-point (m) of the line between P1 and P2:
Pm = (xm, ym, zm)
xm = (x1 + x2) / 2
ym = (y1 + y2) / 2
zm = (z1 + z2) / 2
- Calculate the length to the mid-point of the line between P1 and P2:
Lm = sqrt( xm2, ym2, zm2 )
- Calculate the ratio of the sphere's radius to the length of the mid-point:
k = R / Lm
- Calculate the mid-point along the arc:
Am = k * Pm = (k * xm, k * ym, k * zm)
For P1 to P2, create two edges:
The two edges will cut through the sphere. To solve this, calculate the mid-points between P1Am and AmP2. The more mid-points, the more closely the line segments will follow the sphere's surface.
As Blender is rather precise with its calculations, the resulting arc will likely be (asymptotically) hidden by the sphere. Once you have created the triangular mesh, move it away from the sphere by a few units (like 0.01 or so).
Use a Spline
Another solution is to create a spline from the following:
- sphere's radius (calculated as above)
- P1
- Am
- P2
The resulting splines must be moved in front of the sphere.
Blender Artists Forums
The Blender experts will also have great ideas on how to solve this; try asking them.
See Also
http://www.mathnews.uwaterloo.ca/Issues/mn11106/DotProduct.php
http://cr4.globalspec.com/thread/27311/Urgent-Midpoint-of-Arc-formula