This is a simple example of creating one object from vertices and edges using sin function.
First, you need to create the mesh with bpy.data.meshes.new.
The number is random, you can use any number for vertices and edges.
This number is points for drawing the sin function.
The spaces variable is the range from these points.
Using for statements we can draw the sin function.
The last step is to add all of this into one object named sin.
This object will be linked to the scene.
See the source code of this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import bpy import numpy as np from math import sin sin_mesh = bpy.data.meshes.new( 'sin' ) n = 360 sin_mesh.vertices.add( n ) sin_mesh.edges.add( n - 1 ) spaces = np.linspace( 0, 10, 360 ) for i, y in zip( range(n), spaces ): sin_mesh.vertices[i].co = ( 0, y, sin( y ) ) print (sin_mesh.vertices[i].co) if i < n - 1: sin_mesh.edges[i].vertices = ( i, i+1 ) sin_obj = bpy.data.objects.new( 'sin', sin_mesh ) bpy.context.scene.objects.link(sin_obj) |