Jump to content

Orient away from object


jonidunno

Recommended Posts

Hello,
I'm trying to wrap my head around this... how could I have the orient of nearby points (possibly with a falloff) point avoid (point away from) a nearby object?

My setup right now consists of copied points on a surface and would love them to directional rotate away from the sphere as it gets close to them... here is a scene file if anyone wants to take a stab!

Capture.thumb.PNG.96e66e86590eb98d45547e245ef5b479.PNG

 

pointAway01.hiplc

Link to comment
Share on other sites

newton's law and try to use this it works
 

function float Kernel(vector r ; float h){
    float q = length(r);
    q /= h;
    float factor =  1.0f / (PI  * h * h * h );

    
    if( q>0 && q<=1){
        float right =  1.0f - 1.5f  * (q * q) * (1.0f - q/ 2.0f) ;    
        return factor * right;
    }
    if(q >1 && q <=2 )
    {
        float left = factor / 4.0f;
        float right = pow(2.0f - q , 3);
        return left*right;
    }
    
    if(q>2)
    {
        return 0;
    }
    return 0;
}


function vector GradKernel(vector r; float h){
    float q = length(r);
    q /= h;
    vector dir = normalize(r);
    float factor =  1.0f / (PI  * h * h * h );
    vector retgrad = set(0,0,0);
    
    if( q<=1){
        retgrad = dir * (factor / h) * (-3.0 * q + 2.25f * q*q);
    }
    
    if( q<2){
        retgrad = dir * (-0.75f * (factor / h) * pow((2.0f - q),2) );
    }
    
    return retgrad;

}

float h = chf("h");
@P.y = Kernel(@P, h);

@N = GradKernel(@P, h);


 

NewtonsLaw.hiplc

news.jpg

Edited by Librarian
  • Like 1
  • Thanks 2
Link to comment
Share on other sites

1 hour ago, Librarian said:

newton's law and try to use this it works
 


function float Kernel(vector r ; float h){
    float q = length(r);
    q /= h;
    float factor =  1.0f / (PI  * h * h * h );

    
    if( q>0 && q<=1){
        float right =  1.0f - 1.5f  * (q * q) * (1.0f - q/ 2.0f) ;    
        return factor * right;
    }
    if(q >1 && q <=2 )
    {
        float left = factor / 4.0f;
        float right = pow(2.0f - q , 3);
        return left*right;
    }
    
    if(q>2)
    {
        return 0;
    }
    return 0;
}


function vector GradKernel(vector r; float h){
    float q = length(r);
    q /= h;
    vector dir = normalize(r);
    float factor =  1.0f / (PI  * h * h * h );
    vector retgrad = set(0,0,0);
    
    if( q<=1){
        retgrad = dir * (factor / h) * (-3.0 * q + 2.25f * q*q);
    }
    
    if( q<2){
        retgrad = dir * (-0.75f * (factor / h) * pow((2.0f - q),2) );
    }
    
    return retgrad;

}

float h = chf("h");
@P.y = Kernel(@P, h);

@N = GradKernel(@P, h);


 

NewtonsLaw.hiplc

news.jpg

 

Thanks! I will take a look appreciate you taking to the time to look.

 

 

Link to comment
Share on other sites

Hi jon,

this is how you could map distance and direction towards a surface into an orient attribute:

float dist_min = chf('min_distance');
float dist_max = chf('max_distance');
float angle_max = chf('max_angle');

vector pos = minpos(1, v@P);
float dist = distance(pos, v@P);
vector dir = normalize(pos - v@P);

float mask = 1.0 - smooth(dist_min, dist_max, dist);
float angle = radians(angle_max) * mask;
vector axis = normalize(cross(dir, v@N));

p@orient = quaternion(angle, axis);

image.png.7f8a7ad600c5ced2fa88f36b9cceb87b.png 

orient_away.hiplc

  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
On 9/10/2021 at 1:38 AM, konstantin magnus said:

Hi jon,

this is how you could map distance and direction towards a surface into an orient attribute:


float dist_min = chf('min_distance');
float dist_max = chf('max_distance');
float angle_max = chf('max_angle');

vector pos = minpos(1, v@P);
float dist = distance(pos, v@P);
vector dir = normalize(pos - v@P);

float mask = 1.0 - smooth(dist_min, dist_max, dist);
float angle = radians(angle_max) * mask;
vector axis = normalize(cross(dir, v@N));

p@orient = quaternion(angle, axis);

image.png.7f8a7ad600c5ced2fa88f36b9cceb87b.png 

orient_away.hiplc

Hey Konstantin, 

Appreciate it!  

Link to comment
Share on other sites

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...