Jump to content

link two points with a curve in vex


davidyannick

Recommended Posts

Hi,

if you want to draw a curve automatically from point A to point B you can use the inbuild VEX spline() function for example. spline() takes an array of multiple points, which will be evaluated as curve. You can use the surface normals from the points position using xyzdist() to get the define the direction of the curve. This is of course not the only way to get a round curve from A to B.

Here is an example ...

 

spline_curve_two_points.hipnc

  • Like 1
Link to comment
Share on other sites

Hi, Yes there is a way. Here is the hip file, the HDA and a bit of mansplaining. 

Since you want to make a 2D curve it's best to start by defining the plane on which the curve can exist. That will be the a combination of two vector 1.) The one that goes from pt1 to pt2 (lets refer to it as our x-axis) and 2.) The one that goes perpendicularly away from the geo (we will reffer to this one as y). The x-axis will simply be a subtraction of the two @P vectors, cause if you subtract two vectors you get a vector that starts from one and ends on the other. The y-axis can be any vector that has a right angle on the x-axis. But for our purposes we want the curve to get away from the geo, so we can just use the points @N vector, they are pretty perpendicular. Now this is important, we will use linear combination to get the vector into the right place and then we will addpoint and addprim as many times as there are divisions. Linear combination is any formula that can be written like this:  a*x + b*y = w  where x,y and w are vectors and a and b are scalars. So basically it says you got these two vector, move 'a' amount of time in the vector 'x' direction and then move 'b' amount of times in vector 'y' direction, then you'll arrive at 'w'. Now, if our curve has 4 segments, that means we have to make 4 steps towards it and the length of the step is 1/4. So our 'a' is step length. When we get to our first point (a*x) we are a quarter of the way there and we look up in our ramp that 0.25 means we should be heading some amount in y direction (lets say whooping 5 units ). So our first vector is at w = 1/4*x + 5*y

Hope this helps, don't hesitate to ask if something needs asking :)

The hda uses a icon made by Vincent Thomas

//Points to connect and their main attributes
int Pt1 = chi("Point_1");
int Pt2 = chi("Point_2");

vector Pt1pos = point(0,"P",Pt1);
vector Pt2pos = point(0,"P",Pt2);
vector Pt1nor = point(0,"N",Pt1);
vector Pt2nor = point(0,"N",Pt2);

//If we want the curve to be in a flat xy axis then we need to tell it what the axis will be
//Heading will be our x and up will be our y
//The resulting curve will be a linnear combination of these two axis.
vector heading = Pt2pos - Pt1pos;
vector up = (Pt1nor+Pt2nor)/2;

float mult = chf("Multyplier");
int div = chi("Segments");
float step = 1.0/div;
int start=-1 , end=-1;

for(int i=0 ; i<div+1 ; i++){
    start = end;
    //This one line directly below shadows a previus statment
    //with this one, the line wont be flat but a smooth transition from one normal to the other
    up = (Pt1nor*(1-step*i) + Pt2nor*step*i)/2;
    up = normalize(up)*mult;
    float upValue = chramp("Curve", step*i);
    vector new = Pt1pos + heading*step*i + up*upValue;
    end = addpoint(0,new);
    if(i != 0){
          int segment = addprim(0,"polyline",start,end);
          setprimgroup(0,"line",segment,1,"set");
          }
    }

 

ForDavid.hipnc

Robert_point_connector.hdanc

Curve.jpeg

  • Like 3
Link to comment
Share on other sites

  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...