Skip to content
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

ZMT zurich med tech

  1. Home
  2. Sim4Life
  3. how to model a bent wire with a fixed length?

how to model a bent wire with a fixed length?

Scheduled Pinned Locked Moved Sim4Life
10 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saya
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    1
    • PeterStijnmanP Offline
      PeterStijnmanP Offline
      PeterStijnman
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Saya
        wrote on last edited by Saya
        #3

        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.

        1 Reply Last reply
        0
        • PeterStijnmanP Offline
          PeterStijnmanP Offline
          PeterStijnman
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          1
          • S Offline
            S Offline
            Saya
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • PeterStijnmanP Offline
              PeterStijnmanP Offline
              PeterStijnman
              wrote on last edited by
              #6

              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:)

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Saya
                wrote on last edited by
                #7

                Great. Thanks for your help.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Saya
                  wrote on last edited by
                  #8

                  Hey,

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

                  Thanks.

                  1 Reply Last reply
                  0
                  • PeterStijnmanP Offline
                    PeterStijnmanP Offline
                    PeterStijnman
                    wrote on last edited by
                    #9

                    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)[0]
                    	return wire.GetLength()
                    	
                    	
                    def Thicken_Wire(spline,radius,flagDelete):
                    	wire = XCoreModeling.GetWires(spline)[0]
                    	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
                    	Wire1 = XCoreModeling.CreateSolidCylinder(startVec,Vec3(startVec[0]-height,startVec[1],startVec[2]),radius)
                    	# do the bending
                    	XCoreModeling.BendBodyToCurve(Wire1,startVec,Vec3(startVec[0]-height,startVec[1],startVec[2]),Vec3(0,0,1),target_curve)
                    	
                    	# remove the used spline 
                    	if flagDelete:
                    		spline.Delete()
                    	
                    	return Wire1
                    	
                    	
                    def CreateRandomWire(radiusWire,radiusIns,randomness,flagDeleteSplines):
                    	# 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.0,20.0*(j+1)))
                    		# uncomment for random x and y coordinate
                    		points.append(Vec3(xCor[j][0],yCor[j][0],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
                    	if radiusIns > 0.0:
                    		Ins  = Thicken_Wire(a,radiusIns,False)
                    		Wire = Thicken_Wire(a,radiusWire,flagDeleteSplines)
                    		return Wire,Ins
                    	else:
                    		Wire = Thicken_Wire(a,radiusWire,flagDeleteSplines)
                    		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.
                    	
                    
                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Saya
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • M mkn referenced this topic on
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Search