Blender (jusqu'à 2.49)
Python
Calculer le chemin le plus court 
entre deux lignes 
    Début   Index
précédentScript Python
pytex_wireeffect.htm Suivant

Ma proposition de script pour le problème posé sur Elysiun en Aout 2004 : Help converting from C to Python!

Voir aussi:
Comment trouver le point d'intersection de deux segments coplanaires
Comment trouver la plus courte distance d'un point à une ligne 


import Blender
from Blender  import NMesh
##   Calculate the line segment PaPb that is the shortest route between
##   two lines P1P2 and P3P4. Calculate also the values of mua and 
##    mub where
##      Pa = P1 + mua (P2 - P1)
##      Pb = P3 + mub (P4 - P3)

def LineLineIntersect(p1,p2,p3,p4):
    EPS=0.0000001
    var = 0
    p13, p43 = [0,0,0],[0,0,0]
    p21 = [0,0,0]

    p13[0] = p1[0] - p3[0]
    p13[1] = p1[1] - p3[1]
    p13[2] = p1[2] - p3[2]
    p43[0] = p4[0] - p3[0]
    p43[1] = p4[1] - p3[1];
    p43[2] = p4[2] - p3[2];

    if (abs(p43[0])  < EPS) and (abs(p43[1])  < EPS) and (abs(p43[2])  < EPS):
        var = 0
    else:
        var = 1
    p21[0] = p2[0] - p1[0];
    p21[1] = p2[1] - p1[1];
    p21[2] = p2[2] - p1[2];
    if (abs(p21[0])  < EPS) and (abs(p21[1])  < EPS) and (abs(p21[2])  < EPS):
        var = 0
    else:
        var = 1
    d1343 = p13[0] * p43[0] + p13[1] * p43[1] + p13[2] * p43[2]
    d4321 = p43[0] * p21[0] + p43[1] * p21[1] + p43[2] * p21[2]
    d1321 = p13[0] * p21[0] + p13[1] * p21[1] + p13[2] * p21[2]
    d4343 = p43[0] * p43[0] + p43[1] * p43[1] + p43[2] * p43[2]
    d2121 = p21[0] * p21[0] + p21[1] * p21[1] + p21[2] * p21[2]

    denom = d2121 * d4343 - d4321 * d4321
    print denom
    if (abs(denom) < EPS):
        var = 0
    else:
        var = 1
    numer = d1343 * d4321 - d1321 * d4343
    if var==1:
      mua = numer / denom
      mub = (d1343 + d4321 * (mua)) / d4343
      pa=[0.0,0.0,0.0]
      pb=[0.0,0.0,0.0]

      pa[0] = p1[0] + mua * p21[0]
      pa[1] = p1[1] + mua * p21[1]
      pa[2] = p1[2] + mua * p21[2]
      pb[0] = p3[0] + mub * p43[0]
      pb[1] = p3[1] + mub * p43[1]
      pb[2] = p3[2] + mub * p43[2]

      return [var, pa, pb, mua, mub]
    else:
      return [var]
try:
  O=Blender.Object.GetSelected()[0]
  me=O.getData()
  S=[s for s in me.verts if s.sel==1]
  for s in S: s.sel=0
  print S
  z=len(S)
  print z 
  while z>=4:
        p1=S[z-4] 
        p2=S[z-3] 
        p3=S[z-2] 
        p4=S[z-1] 
        coord=LineLineIntersect(p1,p2,p3,p4)
        print coord
        f=NMesh.Face()
        for p in [p1,p2]: f.append(me.verts[me.verts.index(p)]) 
        f=NMesh.Face()
        for p in [p3,p4]: f.append(me.verts[me.verts.index(p)]) 
        me.faces.append(f)
        if coord[0]==1: 
           v=NMesh.Vert()
           for n in [0,1,2] : v[n]=coord[1][n]
           me.verts.append(v)
           v=NMesh.Vert()
           for n in [0,1,2] : v[n]=coord[2][n]
           me.verts.append(v)
           f=NMesh.Face()
           for n in [-1,-2] : f.append(me.verts[n]) 
           me.faces.append(f)
           me.update() 
        z-=1
except:
  pass 


 
précédentScript Python
Script uv2mesh Suivant
Vers le  Haut de page

Les questions concernant cette page  peuvent être posées sur  :
 news://news.zoo-logique.org/3D.Blender


 

 

Livre en français
Blender : apprenez, pratiquez, Créez, livre, Ed. Campus Press, coll. Starter Kit
Blender Starter Kit

Forum
FAQ
Lexique
Didacticiels
Compilations
Blender2KT
Débuter
Modelage
Blender python
Materiaux
Lumière
Animation
API python (eng)
Archives nzn
Statistiques
Doc flash Sculptris
Galerie Sculptris

mon site de démos sur youtube