Grasshopper

algorithmic modeling for Rhino

anybody know the syntax to resize an On3dPointArray?

Views: 632

Replies to This Discussion

Why do you need to resize it?

On3dPointArray is a dynamic array. You can append new points and it will resize itself to accomedate new items. To see all utility function of On3dPointArray you can see the auto-complete:
Dim points as new On3dPointArray
'point."a list of functions will show"

This is a sample of how to append new points:

Dim points as new On3dPointArray
Dim pt as new On3dPoint(0,0,0)
points.Append(pt)
yeah, I thought so, but it didn't look like it was working. now it seems fine...thanks
I'm trying to convert an old rhinoscript to .net but I feel like I'm missing something really trivial but still causing problems -see anything funny? I think there's something wrong with the vectors but I can't pinpoint it

original script:

vec = Rhino.VectorCreate(crvPt, gripPos)
vec = Rhino.VectorScale(vec, ratio)
newPos = Rhino.VectorAdd(vec, gripPos)
Rhino.ObjectGripLocation crvArr(i), j, newPos

.Net conversion:
vec.Set(crvPt.x - gripPos.x, crvPt.y - gripPos.y, crvPt.z - gripPos.z)
Dim scale As New OnXform(ratio)
vec.Transform(scale)
newPos.Set(gripPos.x + vec.x, gripPos.y + vec.y, gripPos.z + vec.z)
Dim finalPos As New On4dPoint(newPos)
crvA.SetCV(k, finalPos)
Hi Gabriel
This is not trivial question.

Because RhinoScript wraps many of the RhinoSDK functions, it is not very straight forward to write a parallel code in VB.NET in many cases.

Let me try to answer your question.

If you have 2 points: p0=crvPt and p1=gripPos, then a vector in vb.net would be declared as follows:
Dim vector as new On3dVector(p0,p1) 'Easier ha?

When you need to get the unit vector, you do the following:
vector.Unitize()

Scaling a vector is:
vector = vector*scale_factor ' Easier still?

Now the harder part which is if you want to move grip or control point of a curve by some vector. This is how you might do it:

'suppose your nurbs curve is called nc:
Dim cv_pt as new On_3dPoint
nc.GetCV(index,cv_pt)
cv = cv*vector
nc.SetCV(index, cv)


I also recommend that you check the Grasshopper Primer, it has many examples that should help.

Let me know if this is what you are after.
yeah, that's really helpful. I was doing much more work in order to do what is actually really simple - and I wouldnt have figured it out without your help...

so, one quick thing, in your example, the cv = cv*vector - should this actually be cv_pt = cv_pt*vector
Yes, every cv is meant to be cv_pt. Sorry about that.
I think another reply I made got lost in the shuffle. justbriefly - the constructor you just introduced me to for on3dvectors is not working for some reason. Not only does it not show up as an option when I get to the first parentheses but when I write it anyways it trips up the script all together...any idea why?
Oops,
A vector is represented by 3 numbers, similar to a point.
A vector between 2 points is:
vector = to_point - from_point

So this is how you can get it:
Dim vector As New On3dVector()
vector = p1 - p0
again, a post I made didn't show up...
stilll having trouble and based on my debugging attempts there's something problematic with the line:

cv = cv*vector

I am getting an output message that says that a value of type double cannot be converted to an on3dpoint...any ideas why?
Gabriel,
cv = cv+vector

Here is a sample with 2 ways to move a point by some vector:
MovePoint.PNG
MovePoint.ghx
Gabriel,

did you want to either upload your VB component or publish the entire code - it's too difficult to ascertain where your problem may lie from just one line. Not entirely sure of what you're trying to achieve but there is a similar tutorial by Rajaa in the Primer. I may be wrong in suspecting that you are working explicitly with curves but am quite sure that On4dPoint is relevant to OnNurbsSurface.
thanks for the offer, here's the code - basically I'm trying to get curves within some proximity to be drawn towards each other and bundle by modifying the closest cv point

Sub RunScript(ByVal crvArr As List(Of OnCurve), ByVal steps As Integer, ByVal threshold As Double, ByVal ratio As Double)

Dim k, h, count, gripCount As Integer
Dim i, j, closeCrvInd As New int32
Dim gripPos, crvPt As New On3dPoint
Dim crvParam, dist As New Double
Dim arrCrvPts As New On3dPointArray

Dim newPos, vec As New On3dVector

Dim nurbsCrv As New OnNurbsCurve

Dim newCrvs As New List(Of OnCurve)

Dim newPts As New List(Of On3DPoint)

'number of steps
For h = 0 To steps Step 1

For i = 0 To crvArr.Count - 1
nurbsCrv = crvArr(i).NurbsCurve

gripCount = nurbsCrv.m_cv_count

For j = 0 To gripCount - 1

'gripPos = crvA.GetCV(j, gripPos)
nurbsCrv.getcv(j, gripPos)

Dim tempPt As New On3dPoint(gripPos.x, gripPos.y, gripPos.z)
newPts.Add(tempPt)

'for each of the control points
count = 0

For k = 0 To crvArr.Count - 1

If i <> k Then

crvArr(k).GetClosestPoint(gripPos, crvParam)
crvPt = crvArr(k).PointAt(crvParam)
arrCrvPts.Append(crvPt)

End If
Next

arrCrvPts.GetClosestPoint(gripPos, closeCrvInd)

crvPt = arrCrvPts(closeCrvInd)

dist = gripPos.DistanceTo(crvPt)

If dist < threshold Then

vec = gripPos - crvPt
vec = vec * ratio
gripPos = vec

gripPos = gripPos * vec

nurbsCrv.SetCV(k, gripPos)

End If
Next

'newCrvs.Add(crvA)
crvArr(i) = nurbsCrv
Next

Next

A = crvArr
B = newPts

End Sub

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