Grasshopper

algorithmic modeling for Rhino

hi all,

 

I am trying to write an attraction and repulsion script in VB ,but at the moment I have this problem which my points moves away till infinitey,I guess.....I know I need to write some threshold for it,but I did this for max and min distance,but still moves away....I just want a fraction of moments.....can somebody help me and tell me how I can fix this script,pleaseeeeeeeeee!!!!!!

this is for the positive points:

 

 Dim vectorlength As Double
          vectorlength = saharsvector.Length()

          If(vectorlength < min) Then
            vectorlength = min
          End If

          'if vectorlength is larger than our max value
          If (vectorlength > max) Then

            'then make the modifier 0 instead of 1/vector length
            modifier = 0
            'otherwise
          Else

            modifier = 1 / vectorlength

 

this is for the negative points:

 

Dim vectorlength As Double
        vectorlength = sepidvector.Length()
        If(vectorlength > max) Then
          vectorlength = max
        End If
        If(vectorlength < min) Then
          vectorlength = 1000
        End If

        'if vectorlength is larger than our max value
        If (vectorlength > max) Then

          'then make the modifier 0 instead of 1/vector length
          modifier = 0
        Else
          modifier = 1 / vectorlength

 

and please, I am beginner in scripting and know a little....

 

thx alotttttttttt

Views: 998

Replies to This Discussion

Here's the code for an attractor i did recently. It follows Coulomb's law but you can ignore all that and use a simpler equation.


' BORDES
If p.DistanceTo(bo.ClosestPointTo(p)) < 0.01 Then
a = p
Return
End If
'

Dim ptlist As New list(Of Point3d)
Dim pn As point3d = p
ptlist.add(pn)

Dim k As Double = 1 / (4 * math.PI * (8.85 * 10 ^ -12))
Dim vvect As vector3d = New Vector3d(0, 0, 0)

For j As Integer = 1 To it
Dim fvect As New Vector3d(0, 0, 0)

For i As Integer = 0 To ps.Count - 1
Dim vtemp As New Vector3d(0, 0, 0)
Dim f As Double = 0
Dim val As Double = 1 - v(i)
vtemp = ps(i) - pn
Dim dist As Double = vtemp.Length
If dist < r Then dist = r

' LEY COULOMB
f = k * ((q * q * val) / (dist ^ e))
' LEY MODIFICADA
' f = k * ((q * q * val ^ e2) / (dist ^ e))

vtemp.Unitize
vtemp = vtemp * f
fvect = fvect + vtemp
Next
Dim avect As Vector3d = fvect / m

' MRUA
' vvect = vvect + avect * t
' pn = pn + vvect * t + 1 / 2 * avect * t ^ 2

'LINEAL
vvect = avect * t
pn = pn + vvect

ptlist.add(pn)
Next

a = ptlist



Inputs are 'p' as the point to move, 'ps' as a list of attractor points, 'v' as a list of charge values, 'r' as a minimum radius used for not ending up in a singularity, 'it' as number of iterations, 't' as the time increment in every iteration, the rest are related to physical properties that can be simplified.
thanks for your reply...but I need 2 points which they will define as positive and negative one and they should repel or attract each other on a base of attraction and repulsion law.....i tried to run your script tahty you send me here,but it seems it doesn't work.....anyway,thx for yr reply

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service