Grasshopper

algorithmic modeling for Rhino

hi,
i'm pretty new in scripting and i'm wonering how i can map one domain {0 to 3} to another {0 to 1}. so if the value 1.5 the new/mapped value would be 0.5. i know there is a command in processing which is called "map(value, start_target, end_target, start, end)" but it doesn't work in the vb/c#-component...

vb
Private Sub RunScript(ByVal x As List(Of Double), ByVal lichtehoehe As Object, ByRef A As Object)
    Dim i, x_length As int32
    Dim temp As Double
    Dim ausgabe(x.count-1) As Double
    x_length = x.count - 1

    For i = 0 To x_length
      temp = 0 + x(i)
      temp = map(temp, 0, 1, 0, lichtehoehe)
      ausgabe(i) = temp
    Next
    a = ausgabe

c#
  private void RunScript(List<int> x, int lichtehoehe, ref object A)
 {
    int temp = 0;
    int x_length = x.Count - 1;
    int[] ausgabe = new int[x.Count];

    for (int i = 0;i < x_length; i++)
    {
      temp = 0 + x[i];
      temp = map(temp, 0, 1, 0, lichtehoehe);
      ausgabe[i] = temp;
    }
    A = ausgabe;
}


thank you for your help
boris

Views: 798

Replies to This Discussion

You'd first compute the 'normalized' parameter, then 'evaluate' the other domain at that parameter.

t_normal = (p - i0) \ (i1 - i0)

where p is the parameter, and i0 & i1 are the extremes of domain A

t_map = j0 + t_normal * (j1 - j0)

where j0 & j1 are the extremes of domain B


Both OnInterval (in the old SDK) and Geometry.Interval (in the new SDK) have methods that allow you to convert between normalised parameter and regular parameters.

--
David Rutten
david@mcneel.com
Turku, Finland
Hi David,

Any way to make this just with grasshopper components? Not writting in VB..

Cheers!!
thank you very much !!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service