Grasshopper

algorithmic modeling for Rhino

I'm new to VB coding in GH, and I would like to develop a recursive loop that draws a line from a point through the tangent edge of a circle, creates a new circle at the end of the line, and draws a new line from the same origin point through the tangent edge of the second circle, and so on to some specified number of circles are drawn.

Is there a way to extract the VB script from the GH component (Tangent Edge)? If not I where do I start with something like this?

I actually have a grasshopper definition that deals with this, but I have to continuously copy a certain section of the definition over and over.  I'm trying to avoid this with the VB editor.

Any suggestions would be helpful, Thanks!

Views: 505

Replies to This Discussion

I did a little digging, and I did find OsnapModes and the tangent enumeration, but how exactly do I use it?

If you're just dealing with lines and circles in 2D I recommend using trigonometry to solve your problem. I attached the function I wrote for the [Tangent Lines] component.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Attachments:
Thanks David,

I figued it out. I used the following code the solve for a tangent line from a given point to a given circle. It works well, and is modified to draw only the tangent line on the top half of the circle.

Private Sub RunScript(ByVal inputPoint As Point3d, ByVal inputCircle As Circle, ByRef A As Object, ByRef B As Object, ByRef C As Object)
Dim radius As Double = inputCircle.Radius
Dim length As Double = Math.abs(inputPoint.X - inputCircle.Center.X) + radius
Dim height As Double = Math.Tan(Math.Atan(height / length)) * length
Dim tanAngle As Double = Math.Atan(height / length)

Dim lineGuide As New Line(inputPoint, inputCircle.Center)
Dim theta As Double = Math.Acos(radius / lineGuide.Length)

Dim rotAxis As New Vector3d(0, 0, 1)
Dim lineGuideVec As New Vector3d(inputCircle.Center.X - inputPoint.x, inputCircle.Center.y - inputPoint.Y, inputCircle.Center.z)

lineGuideVec.Rotate(-1 * Math.PI / 2, rotAxis)

Dim lineCutAtCos As New Line(inputPoint, inputCircle.Center - inputPoint, lineGuide.Length - radius * Math.Cos(theta))
Dim rotateLine As New Line(lineCutAtCos.To, lineGuideVec, radius * Math.Sin(theta))

If rotateLine.From.Y > rotateLine.To.Y Then
lineGuideVec.Rotate(Math.PI, rotAxis)
Dim rotateLine2 As New Line(lineCutAtCos.To, lineGuideVec, radius * Math.Sin(theta))
Dim finalLine As New Line(inputPoint, rotateLine2.To)
C = finalLine
A = rotateLine2
print("a")
Else
Dim rotateLine3 As New Line(lineCutAtCos.To, lineGuideVec, radius * Math.Sin(theta))
Dim finalLine As New Line(inputPoint, rotateLine3.To)
C = finalLine
print("b")
A = rotateLine3
End If

Dim xLine As New Line(inputPoint.X, inputPoint.Y, inputPoint.Z, inputPoint.X - length, inputPoint.Y, inputPoint.Z)

B = lineCutAtCos
End Sub


Aside from this I am getting an error when I open the VB component in any GH file. (there is an error in XML document (0,0)). I can exit from this warning window and open the script component, but its rather annoying. Any ideas?

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service