Hi,
I have selected a surface edge, is this a way to know surface’s edge is going in the U direction or the V direction ?
CRhinoGetObject go;
go.SetCommandPrompt(L"select surface edge");
go.SetGeometryFilter(CRhinoGetObject::curve_object);
go.GetObjects(1, 1);
if (go.CommandResult() != CRhinoCommand::success)
{
return;
}
const CRhinoObjRef& objRef = go.Object(0);
const ON_BrepEdge* edge = objRef.Edge();
ON_Brep* br = objRef.Edge()->Brep();
private void RunScript(Surface surface, List edgeList, ref object A)
{
var nurbSrf = surface.ToNurbsSurface();
List<String> values = new List<String>();
for (int i = 0; i < edgeList.Count; i++)
{
var length = edgeList[i].GetLength();
if ( length > nurbSrf.IsoCurve(0, 0).GetLength() - 0.001 && length < nurbSrf.IsoCurve(0, 0).GetLength() + 0.001 )
{
values.Add("U");
}
else
{
values.Add("V");
}
}
A = values;
}
Surfacee Edge direction.gh (8.2 KB)
Hi@ mahanmotamedi1991,
Thank you for your replay, you gave me a good idea .
But it will have error when the U direction and the V direction of the surface have the same edge length.
dale
(Dale Fugier)
June 16, 2020, 6:16pm
4
Hi @suc_kiet ,
What about this condition, where the edge does not follow the natural boundary of the surface?
Or are you dealing with untrimmed surfaces?
– Dale
Hi@ dale,
I’m sorry I forgot to explain this.
Yes, I just dealing with untrimmed surfaces.
dale
(Dale Fugier)
June 16, 2020, 7:41pm
6
Hi @suc_kiet ,
How about this?
CRhinoCommand::result CCommandTest::RunCommand(const CRhinoCommandContext& context)
{
CRhinoGetObject go;
go.SetCommandPrompt(L"Select edge");
go.SetGeometryFilter(CRhinoObject::curve_object);
go.SetGeometryAttributeFilter(CRhinoGetObject::edge_curve);
go.GetObjects(1, 1);
if (go.CommandResult() != CRhinoCommand::success)
return go.CommandResult();
const CRhinoObjRef& objRef = go.Object(0);
const ON_BrepEdge* edge = objRef.Edge();
if (nullptr == edge)
return CRhinoCommand::failure;
if (edge->IsClosed())
return CRhinoCommand::cancel;
const ON_Brep* brep = edge->Brep();
if (nullptr == brep)
return CRhinoCommand::failure;
if (!brep->IsSurface())
return CRhinoCommand::cancel;
const ON_Surface* srf = brep->m_S[0];
if (nullptr == srf)
return CRhinoCommand::failure;
double u0, u1, v0, v1;
if (
srf->GetClosestPoint(edge->PointAtStart(), &u0, &v0) &&
srf->GetClosestPoint(edge->PointAtEnd(), &u1, &v1)
)
{
if (fabs(u0 - u1) < ON_ZERO_TOLERANCE)
RhinoApp().Print(L"Edge oriented in surface \"V\" direction\n");
else
RhinoApp().Print(L"Edge oriented in surface \"U\" direction\n");
}
return CRhinoCommand::success;
}
– Dale
private void RunScript(Surface surface, List edgeList, ref object A)
{
var nurbSrf = surface.ToNurbsSurface();
List<String> values = new List<String>();
for(int i = 0; i < edgeList.Count; i++)
{
var crv = edgeList[i];
var iCrv = nurbSrf.IsoCurve(0, 0);
var stPt = crv.PointAt(0);
var endPt = crv.PointAt(1);
var stPtI = iCrv.PointAt(0);
var endPtI = iCrv.PointAt(1);
Vector3d vec1 = endPt - stPt;
Vector3d vec2 = endPtI - stPtI;
if( vec1.IsParallelTo(vec2) == 1 || vec1.IsParallelTo(vec2) == -1)
{
values.Add("U");
}
else
{
values.Add("V");
}
}
A = values;
This will work if your surface is not freeform
Surfacee Edge direction_Edited.gh (6.0 KB)
Hi@ mahanmotamedi1991,
Thank you.