Grasshopper

algorithmic modeling for Rhino

I wants to orient an object inside a VB-component, is it possible to call the “orient” function or do I have to make my own function?

Views: 1211

Replies to This Discussion

Hi Morten,

Do you mean you want to call a function that does something similar to what GH orient component does?
If so, this is not possible. Inside a VB node, you'll have to create your own definition.
Hi Rajaa...

Exactly , well then I have to do it the hard way, thank you for your reply!
If I understand you correctly its actually not too hard. The orient function implements what's referred to as a Change Basis transformation (it actually says this if you hover over it), which basically maps one plane onto another. This transformation is supported by the OnXform class, so if you have the two planes then it can work exactly the same. Attached is a recreation of the Orient component with VB.NET. As you'll see its next to nothing to recreate. The only gotcha is remembering which plane to supply to the function first...

-Damien
Attachments:
Woot!
...actually, on further review, I'm having a hard time getting this to work correctly when I apply different planes than ones oriented at the world origin. The orient component does the trick just fine, but the script component as written gets wacky. Is there something wrong with my code that I can quickly fix?
Attachments:
As I said "the only gotcha is remembering which plane to supply to the function first". It appears that I got that mixed up in the original definition that I posted, and it looks like that's what's going on in your image as well. Switching the planes should have them map correctly.
I'm sure I'm just not getting it...I've tried switching the inputs back and forth, to no avail...but thanks for getting back. I've been able to implement Morten's function below, so I'm all set...
Hi David.

Here is the function I wrote ...Maybe it can help you ..

-------------------------------------------------------------


Function Orient(ByVal ref_pt_01 As On3dPoint, ByVal ref_vec As On3dVector, ByVal srf_normal As On3dVector, ByVal obj As OnBrep, ByVal srf_pt As On3dPoint) As OnBrep

Dim x_coor As New Double
x_coor = srf_pt.x - ref_pt_01.x

Dim y_coor As New Double
y_coor = srf_pt.y - ref_pt_01.y

Dim z_coor As New Double
z_coor = srf_pt.z - ref_pt_01.z

Dim xform_move As New OnXform
xform_move.Translation(x_coor, y_coor, z_coor)

Dim xform_rotate As New OnXform
xform_rotate.Rotation(ref_vec, srf_normal, srf_pt)

Dim orient_obj As New OnBrep(obj)
orient_obj.Transform(xform_move)
orient_obj.Transform(xform_rotate)

Orient = orient_obj

End Function




-----------------------------

Morten
Thank you so much, Morten...this works beautifully and I really appreciate you getting back to me so quickly.
After first applying it by checking a cone, I noticed that the function only oriented the objects on one axis, so I've added a second transformation that rotates the moved brep once more. This allows you to reorient orthogonal elements with edges more precisely to one another:

Function Orient(ByVal ref_pt_01 As On3dPoint, ByVal ref_pt_02 As on3dPoint, ByVal ref_vec As On3dVector, ByVal srf_normal As On3dVector, ByVal obj As OnBrep, ByVal srf_pt As On3dPoint, ByVal srf_pt_02 As On3dPoint) As OnBrep

Dim x_coor As New Double
x_coor = srf_pt.x - ref_pt_01.x

Dim y_coor As New Double
y_coor = srf_pt.y - ref_pt_01.y

Dim z_coor As New Double
z_coor = srf_pt.z - ref_pt_01.z

Dim xform_move As New OnXform
xform_move.Translation(x_coor, y_coor, z_coor)

Dim xform_rotate As New OnXform
xform_rotate.Rotation(ref_vec, srf_normal, srf_pt)

Dim orient_obj As New OnBrep(obj)
orient_obj.Transform(xform_move)
orient_obj.Transform(xform_rotate)

Dim move_pt As New On3dPoint(ref_pt_02)

move_pt.Transform(xform_move)
move_pt.Transform(xform_rotate)

Dim dir_1 As New On3dVector(move_pt.x - srf_pt.x, move_pt.y - srf_pt.y, move_pt.z - srf_pt.z)
Dim dir_2 As New On3dVector(srf_pt_02.x - srf_pt.x, srf_pt_02.y - srf_pt.y, srf_pt_02.z - srf_pt.z)

Dim xform_rotate_2 As New OnXform
xform_rotate_2.Rotation(dir_1, dir_2, srf_pt)
orient_obj.Transform(xform_rotate_2)

Orient = orient_obj

End Function

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