# How to snap an object to another precedurally?

## Recommended Posts

Say I have a cone and a sphere:

I'd like to snap the cone to the closest point on the sphere, along the direction {0, -1, 0}. Like this:

I know Ray SOP, but it snaps every point to the sphere:

I'd like to keep the cone as a cone. Is there a node to do this procedurally?

##### Share on other sites

Add a point underneath, ray and match its position.

match_ray_top.hiplc

##### Share on other sites
Posted (edited)
21 hours ago, konstantin magnus said:

Add a point underneath, ray and match its position.

Thank you!

But I'd like to know how to make it more generic. For example when the ray I cast doesn't align with the world axes (e.g. {0.811, 0.32, 0.48}). I'm trying to make something just like Ray but only ray the closest point, and translate the rest of the geo accordingly. Is it possible?

Edited by raincole

##### Share on other sites

Hi rain,

isolate the closest point and apply its offset vector to all other points.

```vector pos = point(1, 'P', 0);
vector rest = point(1, 'rest', 0);
vector delta = pos - rest;
v@P += delta;```

object_snap.hipnc

##### Share on other sites

Here are some ideas.

• calculate the closest distance to geo for all points and calculate attributes (closest point on target geo or ray projected point, Normal optionally ...)
• find best point (closest point)
• add the target point of the best point (add attributes if needed)
• substract closest point (source) to move object to center (reorient optionally using the direction to center point of the object and up vector the point with highest y-value for example)
• move geo to target point (reorient geo optionally using N,up)

snap_closest_point.hipnc

• 1

##### Share on other sites

what about the match size node?

##### Share on other sites

Compute N and  up for the destination surface, i.e on its points; somehow create the destination point on the surface - it could be a ray, scatter, attribute transfer - anything that interpolates N and up

Create your object with the part you want facing the object towards Z, then put a Match Size: Justify Z: min, the other Justify value depends on your geometry, make sure the tip of your object is on the origin.

Then copy to points SOP.

## Create an account

Register a new account