Grasshopper

algorithmic modeling for Rhino

Hello everyone,

I need to move a point "A" through a surface, so that the new point "B" is at a distance "d" of "A" (in Cartesian coordinates), following a "v" direction.

• I do not know the equation of the surface. This way is out, I guess.
• The shortest path method does not work, because this need the start and end points. What I want to calculate is the final point.
• Rhino methods for the tangent on a surface only work in the U and V direction, I do not know why.

What I've done is fractionate the direction "v", move "A" in small steps and in each of them getting the tangent to the surface in direción "v". This forces me to do Closest point and other operations many times, also it is not accurate. So I wanted to ask if anyone knows a better way. This process will be repeated many times in my algorithm, I need to optimize it.

Thank you.

'Using planes because it is what I need to move in my code. The Z axis of the input and output plane is normal vector to the surface.

Function FlowOnSrf (ByVal Srf As surface, ByVal P As plane, ByVal Dir As vector3d, ByVal steps As Integer) As plane

Dim vel As Double = ( dir.Length() + 0.001) / steps
Dim plane As New plane(P.Origin, dir, p.ZAxis)
Dim counter As Integer = 0
Do While counter < steps
counter += 1
plane.Translate(plane.XAxis * vel)
Dim u,v As New Double
srf.ClosestPoint(plane.Origin, u, v)
plane.Origin = srf.PointAt(u, v)
plane.YAxis = srf.NormalAt(u, v)
Loop
Return New plane(plane.Origin, plane.YAxis)
End Function

Other ways could be to move the point in UV coordinates, but I do not know how to convert the distance and direction to UV coordinates of a given surface.
I think using the sine at each step would be more accurate, but I do not know how.

By the way, I do not need a code, I need a method, so gh definitions are welcome.

Views: 671

### Replies to This Discussion

Long time ago I wrote a 'ToyCar' plugin, which is basically like ShortPath except instead of two end-points it took a startpoint and a direction. I don't entirely recall how I solved it, but I suspect I moved 2 or 3 points different but a small amounts in the requested direction, projected them back onto the surface and used Runge-Kutta to come up with a better position. Repeat until all the steps add up to the desired length.

I did not know the Runge-Katta method, seems to be the best solution for accuracy using this procedure, I will give a try, but my main goal is to optimize runtime, so I have doubts.

Do you know/suspect why rhino gives the curvature in only two directions? You know how they do it? I'm more interested in methods using UV coordinates directly, but this is a good supply of course.

Thanks for the reply David.

I don't know how the surface curvature algorithm works, but I know that the maximum and minimum curvatures of a surface are always at 90 degrees to each other. So Rhino returns the maximum and minimum directions as those are the most interesting. If you want the curvature in a specific direction, you'll have to create a curve over the surface then evaluate the curve. Over short (and I do mean short) distances the surface approximates a flat plane, so you can use the UV parameterization to create a short UV line segment which becomes a short 3D curve once mapped to the surface.

Why can't you just find the closest point from A to the surface and then get the normal vector of the surface at that closest point? Why so much concern with tangents instead of normals? Or just find the closest point and then move A in a point-to-A vector past it as far as you want?

Thanks, but I did not understand your reply. You need the tangent vector to move the point over a surface accurately, like a marble ball in a bowl. The problem is not the tangent vector, because that can be obtained with the normal vector and the direction I want to give (as in the code above), the problem is the method itself, which does not seem optimal. Instead of walking small sections, I would like to remap the surface to match the direction and length values in Cartesian coordinates to the UV coordinates, or something like that, provided that to be more efficient.

Ah, lost in translation your specification was: you said in English you wanted to move "through" a surface, but re-reading the rest implies you want to actually move "along" a surface, which is why tangents are involved. Without a diagram I locked into the idea of plunging straight through from inside to outside of a body.

• View All

## Videos

• ### Parametric Stair (Grasshopper Script)

Added by Parametric House