# how to model a bent wire with a fixed length?

Hello,

I need to model some different bent wires in different shapes, with a fixed length. I define some points first and connect them using lines in sketch and then thicken wire in modify in the ribbon. But at the points location, wires are not smooth and an angle is made. I'm wondering is there any other option to make an smooth bent wire?

Thanks

Hey, you would most likely want to use the "spline" option rather than the actual "line". These are smooth and usually, result in smooth wires. If you by any chance want to a piece of python code to generate random wires let me know :), they won't all be perfectly the same length though.

Thanks.

But the problem is that using spline, I can not make a wire with a straight part and another bent part. I mean when I connect different points, the straight part gets bent as well and it's length gets changed. How this problem could be fixed? And how the length of a spline could be measured?

Thanks.

Okay, maybe you could try to make the straight part of the wire with the line option and then bent part with a spline. Probably feels a bit suboptimal but I think that is the way to go. You can group the 2 entities (parts of the wire) in a single group afterwards.
As for obtaining the length of a spline, you can use the python scripts posted at : https://forum.zmt.swiss/topic/55/how-to-compute-the-length-of-a-spline-using-the-python-api/2 .
Hopefully this helps!

Thanks. Is that possible to connect the two parts as a single wire instead of making a group?

Maybe you can make one object from both wires, however, if you just place the next to each other and give both identical conductivity and permittivity the simulations should treat it as a connected structure:)

Hey,

could you please send me a piece of python code to generate random wires?

Thanks.

Hey,
sure the code is below. Can I ask for what purpose you are modelling random wires?
Cheers,

``````# get spline function to create random wires
import XCore
import os
import XCoreModeling
import s4l_v1 as s4l
import s4l_v1.model as model
import numpy as np
Vec3 = s4l.Vec3

def get_spline_length(spline):
wire = XCoreModeling.GetWires(spline)
return wire.GetLength()

wire = XCoreModeling.GetWires(spline)
target_curve = wire.GetGeometry(transform_to_model_space=True)

# compute the length of the spline
height = get_spline_length(spline)
print(height)
# get the Vec3 of the starting and end points
startVec = target_curve.Eval(0.0)
endVec = target_curve.Eval(height)

# create a cylinder that will be bend to the spline, its height must be the same as the length of the spline
# do the bending
XCoreModeling.BendBodyToCurve(Wire1,startVec,Vec3(startVec-height,startVec,startVec),Vec3(0,0,1),target_curve)

# remove the used spline
if flagDelete:
spline.Delete()

return Wire1

# randomize the x-coordinate
xCor = np.random.rand(10,1)*randomness - randomness/2
# uncomment if you want to randomize y too
yCor = np.random.rand(10,1)*randomness - randomness/2

# set the same starting point for all the wires
points = [Vec3(0.0,0.0,0.0)]

for j in range(10):
# for random x coordinate
#points.append(Vec3(xCor[j],0.0,20.0*(j+1)))
# uncomment for random x and y coordinate
points.append(Vec3(xCor[j],yCor[j],20.0*(j+1)))
# create the random spline
a = model.CreateSpline(points)

# if you want the wire to be insulated set the radius of the Ins higher then 0
# this creates the wires
return Wire,Ins
else:
return Wire

# Start of main script, change parameters as you like here
NumberofWires = 10

#create the separate simulations
for i in range(NumberofWires):
# start by making the random wire with insulation
[RandomWire,RandomIns] = CreateRandomWire(1.25,2.0,15.0,True)
RandomWire.Name = 'RandomWire' + str(i+1)
RandomIns.Name  = 'RandomIns'  + str(i+1)
#possible to make a simulation in the same loop.

``````

Thanks for the code.

Actually I need to model some wires with the fixed length, with one part in the brain in different spots and the remaining out of the brain, It takes a long time to model each one and I'm looking for a way to make them in a shorter time.

Thanks.