2
$\begingroup$

A want to model a several curves to have a perfect sinusoidal structures of specific integer frequencies. Is there any kind of generator for linear waves in curves?

$\endgroup$
4

1 Answer 1

3
$\begingroup$

Sine Curve

Here is the script that would do this (you can set the value of startX, endX and cycles' while calling drawSineWave based on frequency and increase the resolution to take it closer to the perfect sine wave.)

import bpy
import bmesh
import math

def drawSineWave(resolution, startX, endX, cycles, amplitude):

    bm = bmesh.new()    
    step = (endX - startX) / (resolution)
    cycleSteps = resolution/cycles

    x = startX    
    prevVert = None
    for i in range(0, resolution+1):
        magnitude = 2 * math.pi * (i % cycleSteps) / cycleSteps
        y = amplitude * math.sin(magnitude)

        vert = bm.verts.new([x, y, 0])
        if(prevVert != None):
            bm.edges.new([prevVert, vert])
        x += step
        prevVert = vert

    mesh = bpy.data.meshes.new('sine')
    obj = bpy.data.objects.new('sineObj', mesh)
    bpy.context.scene.objects.link(obj)
    bm.to_mesh(mesh)
    obj.select = True
    bpy.context.scene.objects.active = obj
    bpy.ops.object.convert(target='CURVE')

drawSineWave(resolution = 100, startX = 0, endX = 4, cycles = 4, amplitude = 1)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .