# How can I know the surface's edge is going in the U direction or the V direction

**URL:** <https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146>\
**Category:** Rhino Developer\
**Created:** [June 16, 2020, 1:01pm UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146 "2020-06-16T13:01:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![suc\_kiet](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/suc_kiet/32/757791_2.png) [@suc\_kiet](https://discourse.mcneel.com/u/suc_kiet)\
**Post date:** [June 16, 2020, 1:01pm UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146/1 "2020-06-16T13:01:23Z")

</div>

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();

```

![dir](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/3/6/3653cdb25a4dd6dca42a29a248c19844381f1466.png)

---

<div class="post-metadata">

**Author:** ![mahanmotamedi1991](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mahanmotamedi1991/32/668458_2.png) [@mahanmotamedi1991](https://discourse.mcneel.com/u/mahanmotamedi1991)\
**Post date:** [June 16, 2020, 3:10pm UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146/2 "2020-06-16T15:10:48Z")

</div>

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](https://discourse.mcneel.com/uploads/short-url/hfurwRon1lbG92ev02uWBEKriRE.gh) (8.2 KB)

---

<div class="post-metadata">

**Author:** ![suc\_kiet](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/suc_kiet/32/757791_2.png) [@suc\_kiet](https://discourse.mcneel.com/u/suc_kiet)\
**Post date:** [June 16, 2020, 5:55pm UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146/3 "2020-06-16T17:55:22Z")

</div>

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.

 ![2233](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/4/4/449a36105367a9fb5b32f7076e1534d9e2e68ddd.png)

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [June 16, 2020, 6:16pm UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146/4 "2020-06-16T18:16:37Z")

</div>

Hi @suc_kiet,

What about this condition, where the edge does not follow the natural boundary of the surface?

![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/6/0/602b6a1f9e1e143baec69f2b284f0d57d2752dd8.png)  
Or are you dealing with untrimmed surfaces?

– Dale

---

<div class="post-metadata">

**Author:** ![suc\_kiet](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/suc_kiet/32/757791_2.png) [@suc\_kiet](https://discourse.mcneel.com/u/suc_kiet)\
**Post date:** [June 16, 2020, 6:31pm UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146/5 "2020-06-16T18:31:06Z")

</div>

> [@dale](#):
>
> What about this condition, where the edge does not follow the natural boundary of the surface?

Hi@ dale,  
I’m sorry I forgot to explain this.  
Yes, I just dealing with untrimmed surfaces. 😀

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [June 16, 2020, 7:41pm UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146/6 "2020-06-16T19:41:46Z")

</div>

Hi @suc_kiet,

How about this?

```auto
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

---

<div class="post-metadata">

**Author:** ![mahanmotamedi1991](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/mahanmotamedi1991/32/668458_2.png) [@mahanmotamedi1991](https://discourse.mcneel.com/u/mahanmotamedi1991)\
**Post date:** [June 16, 2020, 8:44pm UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146/7 "2020-06-16T20:44:25Z")

</div>

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](https://discourse.mcneel.com/uploads/short-url/kU5qN2hq9xn63cacafPlGgk5bpr.gh) (6.0 KB)

---

<div class="post-metadata">

**Author:** ![suc\_kiet](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/suc_kiet/32/757791_2.png) [@suc\_kiet](https://discourse.mcneel.com/u/suc_kiet)\
**Post date:** [June 17, 2020, 9:07am UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146/8 "2020-06-17T09:07:29Z")

</div>

Hi@dale,  
Thank you.

---

<div class="post-metadata">

**Author:** ![suc\_kiet](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/suc_kiet/32/757791_2.png) [@suc\_kiet](https://discourse.mcneel.com/u/suc_kiet)\
**Post date:** [June 17, 2020, 9:07am UTC](https://discourse.mcneel.com/t/how-can-i-know-the-surfaces-edge-is-going-in-the-u-direction-or-the-v-direction/104146/9 "2020-06-17T09:07:54Z")

</div>

Hi@ mahanmotamedi1991,  
Thank you.
