Emulate Tan and Perp Osnap

Hi all,

I am trying to emulate the perp and tan osnap in my code. This is pretty much how am I doing it on a curve.

void getPerpOsnap(const ON_Curve* crv, ON_SimpleArray<ON_3dPoint> & osnap){
	if(crv){
		if(const ON_PolyCurve* plycrv =  ON_PolyCurve::Cast( crv )){
			int segcount = plycrv->Count();
			for (int pc = 0 ; pc <segcount; pc++ ){
				ON_Curve* crit = plycrv->SegmentCurve(pc);
				ON_NurbsCurve nrbcrv_pc;
				if (0 != crit && crit->IsValid()){
					if(crit->GetNurbForm(nrbcrv_pc)){
						int sp = 0;
						int nonempty_sp = 0;
						while(nonempty_sp < nrbcrv_pc.SpanCount()){
							ON_BezierCurve bez;
							double tp = 0;
							if(nrbcrv_pc.ConvertSpanToBezier(sp, bez)){
								bez.Reparameterize(1);
								CRhinoSnapContext snap_ctxt;
								if(snap_ctxt.PerpSnapToBezier(bez, p0, 0, &tp)){
									double lengthSquared = (bez.PointAt(tp)-pickPoint).LengthSquared();
										if( lengthSquared < relativePointSquaredDistance){
											osnap.Append(bez.PointAt(tp));
										}
								}
								nonempty_sp++;
							}
							sp++;
						}				
					}
				}
			}
		}
	}
}

I might be wrong but I remember in Rhino5 worked fine. At the moment I cannot get the same points I get in the GUI. Same for Tan. Am I extracting the points in the wrong way?

Thanks,
Gennaro

Hi @gennaro,

Can you give me some background info on what you are trying to do? Perhaps there is a better way of calculating this…

– Dale

Dale,

my goal is to have something similar to the perp and tan Osnap. So given a point P0 I would like to find the points Pi on a curve that make the P0-Pi perpendicular or tangent to that curve.
I have found the CRhinoSnapContext::PerpSnapToBezier, which seemed to be the suitable function, but the outcome is different from the Osnap in the GUI.