tags:

views:

127

answers:

5

Suppose you know the three vertices for a spherical triangle. Then how do you draw the sides on a sphere in 3D?

I need some python code to use in Blender 3d modelisation software.

I already have the sphere done in 3D in Blender.

Thanks & happy blendering.

note 1:

i have the 3 points / vertices (p1,p2,p3 ) on the sphere for a spherical triangle but i need to trace the edges on the sphere in 3D

so what would be the equations needed to determine all vertices between each points pair of the triangle on the sphere 3 edges from p1 to p2 - p2 to p3 and o3 to p1

i know it has something to do with the Great circle for Geodesic on a sphere but cannot find the proper equations to do the calculations in spherical coordinates!

Thanks

A: 

One cheap and easy method for doing this would be to create the triangle and subdivide the faces down to the level of detail you want, then normalize all the vertices to the radius you want.

Raceimaztion
the problem is with math in 3D in spherical coordinates what are the equations to calculate the vertices location function of the triangle's side on the sphere?i know it has something to do with the grreat circle but how do you calculate theses great circles ?Thanks
Rickyblender
@Ricky: You do not need great circles; you can use the ratio of mid-point lengths to the sphere's radius.
Dave Jarvis
+3  A: 

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:

  1. Calculate the radius of the sphere:
    R = sqrt( x12 + y12 + z12 )
    
  2. 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
  3. Calculate the length to the mid-point of the line between P1 and P2:
    Lm = sqrt( xm2, ym2, zm2 )
  4. Calculate the ratio of the sphere's radius to the length of the mid-point:
    k = R / Lm
  5. Calculate the mid-point along the arc:
    Am = k * Pm = (k * xm, k * ym, k * zm)

For P1 to P2, create two edges:

  • P1 to Am
  • Am to P2

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

Dave Jarvis
i can program it in python !i have problem with the math equations to dertermine the triangle's edges on the 3D sphere in othe words what how do you calculate the location of vertice on the sphere for each edge of the triangle ?hope it's clear nowThanks
Rickyblender
@Ricky: Let me know if you have not plotted the triangle, yet.
Dave Jarvis
A: 

i do use the blenders' forum but no guaranti to get a clear answer all the time!

that's why i tried here - took a chance

i did the first edge seems to work now got to make a loop to get multi segment for first edge and then do the other edges also

2- other subject i open here a post on bezier triangle patch i know it's not a usfull tool but just to show how it is done have youeseen a python sript to do theses triangel patch and i did ask this questin on blender's foum and no answer also on IRC python and sems to be dead right now probably guys are too busy finishing the 2.5 Beta vesion which should come out in a week or 2

Hey Thanks a lot for this math discussion if i have problem be back tomorrow

happy math and 2.5

Rickyblender
A: 

Great circles

it would have been interesting to see a solution with great circle and see tehsolution in spherical coordinates directly !

but still interesting to do it in the euclidiens space

Thanks

Rickyblender
A: 

ok i used this idea of line segment between 2 points

but did not do it as indicated before

i used an alternative method - Bezier line interpolation**

i parametrize the line with a bezier line then subdivided and calculated as shonw ealier the ratio and angle for each of the subdivided bezier point on the chord and it works very well and very precise

but it would be interesting to see how it is done whit the earlier method but not certain how to do the iteration loop?

how do you load up the python code here just past it with Ctrl-V?

Thanks and happy 2.5

Rickyblender
@Ricky: Yes, I'd be interested in seeing the code. Copy and paste it here.
Dave Jarvis