1
$\begingroup$

I'm either not understanding Euler rotations, misusing trig, or both. Can you make these cones point out from the center? Code, current rendering, and 2d approximation of the appropriate render follow below.

import bpy
from math import pi,atan,asin,acos
import math
import numpy as np


# clear the scene of objects / materials
objs = [ob for ob in bpy.context.scene.objects]
print(objs)
bpy.ops.object.delete({"selected_objects": objs})
objs = [ob for ob in bpy.data.materials]
print(objs)
for item in objs:
    bpy.data.materials.remove(item)

scn = bpy.context.scene

bpy.context.scene.background_set

# min energy for 101 point circle from https://github.com/thoppe/tf_thomson_charges
XYZ_sphere = np.array([[0.90282832, 0.41698735, 0.10498846], [-0.43112575, 0.37235779, 0.82187606], [-0.95190057, -0.17448321, -0.25187481], [-0.57725662, 0.72244198, -0.38059477], [0.58994846, -0.08553543, 0.80289756], [0.69072787, 0.44584937, -0.56930953], [0.36497313, 0.87991019, -0.30422471], [0.05929669, -0.92411179, -0.37749344], [0.79134563, -0.50392449, 0.34616788], [0.85808206, -0.51325538, -0.01625089], [-0.84712797, 0.02731832, -0.53068626], [0.94018706, 0.13434202, 0.31305034], [-0.81459146, -0.53944425, -0.21316814], [-0.25136678, 0.75444362, -0.60632463], [0.1087786, -0.78527831, 0.60951226], [0.40720158, 0.912165, 0.04628046], [0.62731096, -0.41239143, 0.66061658], [0.74946253, 0.51570552, 0.41515508], [-0.99437988, -0.02569715, 0.10270496], [-0.15347446, 0.85365163, 0.49771929], [0.39953094, -0.80395896, -0.4404827 ], [-0.68303595, 0.1548129, 0.71378908], [-0.92595426, -0.37062484, 0.07242888], [0.874153, 0.42003622, -0.24377473], [0.19682973, 0.09735596, 0.97559206], [-0.67342028, -0.19800287, 0.71224995], [-0.37264334, -0.38037191, 0.84643614], [0.1313608, 0.94968443, 0.28433048], [0.34178409, -0.93571135, -0.0873379 ], [-0.60186296, 0.1976192, -0.773762 ], [0.94636543, -0.22626812, -0.23064087], [-0.33570116, -0.9385946, 0.07965499], [0.5412922, -0.2232892, -0.81064461], [-0.85809274, -0.29792526, 0.41823126], [-0.10292856, -0.92560381, 0.36422973], [-0.40432879, -0.00742613, 0.91458356], [0.84213555, -0.15439844, 0.51669028], [0.17244199, 0.47230957, 0.86440004], [0.15176879, -0.70698513, -0.69075195], [0.96399341, -0.2101132, 0.16300043], [-0.89628792, 0.06261232, 0.43903037], [-0.79509306, 0.3869757, -0.46698698], [-0.2588664, 0.92574351, -0.27565764], [0.41054596, 0.68341488, -0.60365231], [-0.60299255, -0.53657305, 0.59032986], [0.28793677, -0.2397256, 0.92715913], [0.50429093, -0.54742848, -0.66784183], [-0.48658698, 0.63797665, 0.59684077], [0.48387041, -0.72325816, 0.49271397], [-0.76689629, -0.37048789, -0.5240313 ], [0.7007117, 0.70905402, 0.07902854], [-0.74226384, -0.62575083, 0.23975047], [0.0912462, 0.62230545, -0.77743814], [0.39849807, 0.39286253, -0.82876916], [-0.56033282, -0.7072634, -0.43105176], [-0.2955867, -0.91388366, -0.27828969], [-0.29371488, 0.12526884, -0.94764935], [-0.46282707, -0.80064777, 0.38046583], [0.07031554, 0.99098573, -0.11403077], [-0.54167505, 0.83914395, -0.04925014], [-0.61570231, -0.78582529, -0.05821751], [0.25886631, -0.92574352, 0.27565771], [0.89201834, 0.11964521, -0.43587647], [-0.21160186, -0.76754925, -0.60505603], [-0.12512186, 0.25084269, 0.95990753], [-0.08248286, -0.15200582, 0.98493188], [-0.52850584, 0.52109611, -0.67017939], [0.06283603, 0.86818549, -0.49224546], [-0.31560155, -0.22917181, -0.92080179], [-0.20249093, 0.97315118, 0.10942675], [-0.74047011, 0.63925103, 0.20751418], [0.75883408, 0.21295328, 0.61548496], [0.60525607, -0.77857514, 0.16578857], [-0.46081719, 0.83175864, 0.30955627], [-0.75897221, 0.42439186, 0.49381448], [-0.23074645, 0.46558214, -0.85439414], [0.01561164, -0.10907782, -0.99391061], [-0.95977514, 0.20165628, -0.1953623 ], [-0.10732215, -0.50653599, -0.85551344], [0.23047266, -0.38426806, -0.89399128], [0.48047163, 0.25128555, 0.8402396 ], [0.65961426, 0.13075466, -0.7401434 ], [0.06328833, 0.27584188, -0.95911722], [0.79618968, -0.19599543, -0.57242273], [-0.25516057, -0.70149241, 0.6654333 ], [-0.14714948, 0.61236968, 0.77675634], [0.31981855, -0.54908697, 0.77215257], [0.18152884, 0.76351555, 0.61975098], [-0.62145477, -0.15431029, -0.76810306], [-0.9301903, 0.33092913, 0.1588456 ], [0.47599019, 0.79118562, 0.38400347], [0.0028764, -0.99992521, -0.01188696], [0.49367349, 0.55835672, 0.66672653], [0.99355134, 0.09098234, -0.06766052], [0.64023201, -0.74508336, -0.18695925], [0.75647931, -0.50759172, -0.41241933], [0.34126191, 0.03753724, -0.93921843], [-0.46937806, -0.51213721, -0.71930502], [-0.81808893, 0.55753881, -0.14099989], [-0.024474, -0.49690316, 0.86746082], [0.65973611, 0.69754679, -0.27960102]]) 
#XYZ_sphere = np.array([[1, 0.0, 0],[0,1,0],[0,0,1],[0.90282832, 0.41698735, 0.10498846]])

for item in XYZ_sphere:
    x = item[0]
    y = item[1]
    z = item[2]
    alpha = atan((-y/x))
    if math.isnan(alpha):
        alpha = pi
    beta = atan(y/(z))
    gamma = -asin(z)
    print((x,y,z,alpha/(pi)*180,beta/pi*180,gamma))
    bpy.ops.mesh.primitive_cone_add(radius1 = .075, radius2 = 0, depth=.25, location=(x,y,z),rotation=(alpha,beta,gamma))

current inccorect render 2d approximation of desired render

$\endgroup$
4
$\begingroup$

Align object to vector.

enter image description here

Use quaternions see Align Object to Vector using python

Sample using data from question.

import bpy
from mathutils import Vector, Matrix

context = bpy.context

XYZ_sphere = ((0.90282832, 0.41698735, 0.10498846),
         (-0.43112575, 0.37235779, 0.82187606),
         (-0.95190057, -0.17448321, -0.25187481),
         (-0.57725662, 0.72244198, -0.38059477),
         (0.58994846, -0.08553543, 0.80289756),
         (0.69072787, 0.44584937, -0.56930953),
         (0.36497313, 0.87991019, -0.30422471),
         (0.05929669, -0.92411179, -0.37749344),
         (0.79134563, -0.50392449, 0.34616788),
         (0.85808206, -0.51325538, -0.01625089),
         (-0.84712797, 0.02731832, -0.53068626),
         (0.94018706, 0.13434202, 0.31305034),
         (-0.81459146, -0.53944425, -0.21316814),
         (-0.25136678, 0.75444362, -0.60632463),
         (0.1087786, -0.78527831, 0.60951226),
         (0.40720158, 0.912165, 0.04628046),
         (0.62731096, -0.41239143, 0.66061658),
         (0.74946253, 0.51570552, 0.41515508),
         (-0.99437988, -0.02569715, 0.10270496),
         (-0.15347446, 0.85365163, 0.49771929),
         (0.39953094, -0.80395896, -0.4404827 ),
         (-0.68303595, 0.1548129, 0.71378908),
         (-0.92595426, -0.37062484, 0.07242888),
         (0.874153, 0.42003622, -0.24377473),
         (0.19682973, 0.09735596, 0.97559206),
         (-0.67342028, -0.19800287, 0.71224995),
         (-0.37264334, -0.38037191, 0.84643614),
         (0.1313608, 0.94968443, 0.28433048),
         (0.34178409, -0.93571135, -0.0873379 ),
         (-0.60186296, 0.1976192, -0.773762 ),
         (0.94636543, -0.22626812, -0.23064087),
         (-0.33570116, -0.9385946, 0.07965499),
         (0.5412922, -0.2232892, -0.81064461),
         (-0.85809274, -0.29792526, 0.41823126),
         (-0.10292856, -0.92560381, 0.36422973),
         (-0.40432879, -0.00742613, 0.91458356),
         (0.84213555, -0.15439844, 0.51669028),
         (0.17244199, 0.47230957, 0.86440004),
         (0.15176879, -0.70698513, -0.69075195),
         (0.96399341, -0.2101132, 0.16300043),
         (-0.89628792, 0.06261232, 0.43903037),
         (-0.79509306, 0.3869757, -0.46698698),
         (-0.2588664, 0.92574351, -0.27565764),
         (0.41054596, 0.68341488, -0.60365231),
         (-0.60299255, -0.53657305, 0.59032986),
         (0.28793677, -0.2397256, 0.92715913),
         (0.50429093, -0.54742848, -0.66784183),
         (-0.48658698, 0.63797665, 0.59684077),
         (0.48387041, -0.72325816, 0.49271397),
         (-0.76689629, -0.37048789, -0.5240313 ),
         (0.7007117, 0.70905402, 0.07902854),
         (-0.74226384, -0.62575083, 0.23975047),
         (0.0912462, 0.62230545, -0.77743814),
         (0.39849807, 0.39286253, -0.82876916),
         (-0.56033282, -0.7072634, -0.43105176),
         (-0.2955867, -0.91388366, -0.27828969),
         (-0.29371488, 0.12526884, -0.94764935),
         (-0.46282707, -0.80064777, 0.38046583),
         (0.07031554, 0.99098573, -0.11403077),
         (-0.54167505, 0.83914395, -0.04925014),
         (-0.61570231, -0.78582529, -0.05821751),
         (0.25886631, -0.92574352, 0.27565771),
         (0.89201834, 0.11964521, -0.43587647),
         (-0.21160186, -0.76754925, -0.60505603),
         (-0.12512186, 0.25084269, 0.95990753),
         (-0.08248286, -0.15200582, 0.98493188),
         (-0.52850584, 0.52109611, -0.67017939),
         (0.06283603, 0.86818549, -0.49224546),
         (-0.31560155, -0.22917181, -0.92080179),
         (-0.20249093, 0.97315118, 0.10942675),
         (-0.74047011, 0.63925103, 0.20751418),
         (0.75883408, 0.21295328, 0.61548496),
         (0.60525607, -0.77857514, 0.16578857),
         (-0.46081719, 0.83175864, 0.30955627),
         (-0.75897221, 0.42439186, 0.49381448),
         (-0.23074645, 0.46558214, -0.85439414),
         (0.01561164, -0.10907782, -0.99391061),
         (-0.95977514, 0.20165628, -0.1953623 ),
         (-0.10732215, -0.50653599, -0.85551344),
         (0.23047266, -0.38426806, -0.89399128),
         (0.48047163, 0.25128555, 0.8402396 ),
         (0.65961426, 0.13075466, -0.7401434 ),
         (0.06328833, 0.27584188, -0.95911722),
         (0.79618968, -0.19599543, -0.57242273),
         (-0.25516057, -0.70149241, 0.6654333 ),
         (-0.14714948, 0.61236968, 0.77675634),
         (0.31981855, -0.54908697, 0.77215257),
         (0.18152884, 0.76351555, 0.61975098),
         (-0.62145477, -0.15431029, -0.76810306),
         (-0.9301903, 0.33092913, 0.1588456 ),
         (0.47599019, 0.79118562, 0.38400347),
         (0.0028764, -0.99992521, -0.01188696),
         (0.49367349, 0.55835672, 0.66672653),
         (0.99355134, 0.09098234, -0.06766052),
         (0.64023201, -0.74508336, -0.18695925),
         (0.75647931, -0.50759172, -0.41241933),
         (0.34126191, 0.03753724, -0.93921843),
         (-0.46937806, -0.51213721, -0.71930502),
         (-0.81808893, 0.55753881, -0.14099989),
         (-0.024474, -0.49690316, 0.86746082),
         (0.65973611, 0.69754679, -0.27960102))

bpy.ops.mesh.primitive_cone_add(
        radius1 = .075,
        depth=.25)

cone = context.object

for v in  XYZ_sphere:
    o = cone.copy()
    context.collection.objects.link(o)
    M = Vector(v).to_track_quat('Z', 'Y').to_matrix().to_4x4()
    M.translation = v
    o.matrix_world = M

bpy.data.objects.remove(cone)    

Note this could also be done using a vertex mesh, verts at locations, and particles or dupliverts, which is far cheaper on resources in comparison to having a separate object for each.

Example using dupliverts

import bpy
from mathutils import Matrix
from math import radians

context = bpy.context

XYZ_sphere = ((0.90282832, 0.41698735, 0.10498846),
         # as above
         (0.65973611, 0.69754679, -0.27960102))

bpy.ops.mesh.primitive_cone_add(
        radius1 = .075,
        depth=.25)

cone = context.object
# dupliverts align Y so rotate such that point is Y
cone.data.transform(
        Matrix.Rotation(radians(-90), 4, 'X'))

me = bpy.data.meshes.new("101Sphere")
me.from_pydata(XYZ_sphere, [], []) # no faces no edges

ob = bpy.data.objects.new("101Sphere", me)
context.collection.objects.link(ob)

# assign the normals since there is no edges faces.
for v in me.vertices:
    v.normal = v.co.normalized()
# duplivert

cone.parent = ob
ob.instance_type = 'VERTS'
ob.use_instance_vertices_rotation = True

Related re equal distribution of points on a sphere https://blender.stackexchange.com/a/102702/15543

$\endgroup$
1
  • $\begingroup$ You are amazing @batFINGER !! Thanks $\endgroup$
    – jb4earth
    Nov 12 '19 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.