Curve.ProjectToBrep problem

Hi,

I want project a Curve over a Brep.

In the image, I’ve the Curve (pink line) and the brep. This Brep is selected and I can see that the vertical line is not in the brep’s middle.

I use this instruction for project the line

Curve curvas = Curve.ProjectToBrep(_linea, Face, Plane.WorldZX.Normal, 1);

And the result is this

The projection result is the green line, but I need the projection over all brep, not only in the section

What can I do?

I’m working with c# and rhinoCommon

Is the Face that you use only the first part?

doc.objects.addbrep(face.duplicate)

to see where you are projecting on?

You maybe got a file and some test code? :slight_smile:

Hi,

My code

 _linea = new Line(ptoMin, ptoMax).ToNurbsCurve();
Curve[] curvas = Curve.ProjectToBrep(_linea, Face, Plane.WorldZX.Normal, 1);
_linea = Curve.JoinCurves(curvas).First();
  • Face is the Brep that I show in the Images
  • the first _linea is the pink line in the first image
  • the second _linea is the green line in the second image

I think that the problem is in the Brep object. Is very rare that if the brep is large, when I selected the brep, the selection middle line is not in the middle’s brep and the line Projectios stop there

Buf… sorry for my english _:slight_smile:

Why you use large tolerance of 1? What is the projection of the pictures (I assume the ZX plane?) Can you post a file that has the problem, and also the code maybe?

If I use the code below on some simple test cases, it works.

ObjRef cRef;
Result res = RhinoGet.GetOneObject("Select curve to project", false, ObjectType.Curve, out cRef);
if (res != Result.Success)
    return res;

ObjRef bRef;
res = RhinoGet.GetOneObject("Select BREP to project to", false, ObjectType.Brep, out bRef);
if (res != Result.Success)
    return res;

Brep b = bRef.Brep();
Curve c = cRef.Curve();

Curve[] result = Curve.ProjectToBrep(c, b, Vector3d.YAxis, doc.ModelAbsoluteTolerance);
if (null != result)
    foreach (Curve crv in result)
    {
        if (null != crv)
            doc.Objects.AddCurve(crv);
    }

doc.Views.Redraw();

Maybe a bit messy but this works for me.
I get a projection. Projection is in the Z-Direction


Imports System
Imports System.Collections.Generic
Imports Rhino
Imports Rhino.Commands
Imports Rhino.Geometry
Imports Rhino.Input
Imports Rhino.Input.Custom

Namespace TestProjectToBrep

    <System.Runtime.InteropServices.Guid("c01eae32-2d3c-4384-88db-4ca680cd90e3")> _
    Public Class TestProjectToBrepCommand
        Inherits Command

        Shared _instance As TestProjectToBrepCommand 

        Public Sub New()
            ' Rhino only creates one instance of each command class defined in a
            ' plug-in, so it is safe to store a refence in a static field.
            _instance = Me
        End Sub

        '''<summary>The only instance of this command.</summary>
        Public Shared ReadOnly Property Instance() As TestProjectToBrepCommand
            Get
                Return _instance
            End Get
        End Property

        '''<returns>The command name as it appears on the Rhino command line.</returns>
        Public Overrides ReadOnly Property EnglishName() As String
            Get
                Return "TestProjectToBrepCommand"
            End Get
        End Property

        Protected Overrides Function RunCommand(ByVal doc As RhinoDoc, ByVal mode As RunMode) As Result

            doc.Objects.UnselectAll()

            Dim Brep As Rhino.DocObjects.ObjRef = Nothing
            Dim rc2 = Rhino.Input.RhinoGet.GetOneObject("Brep", False, Rhino.DocObjects.ObjectType.Brep, Brep)
            If rc2 <> Rhino.Commands.Result.Success Then
                Return rc2
            End If

            doc.Objects.UnselectAll()

            Dim Curve As Rhino.DocObjects.ObjRef = Nothing
            Dim rc = Rhino.Input.RhinoGet.GetOneObject("Curve", False, Rhino.DocObjects.ObjectType.Curve, Curve)
            If rc <> Rhino.Commands.Result.Success Then
                Return rc
            End If

            Dim DefBrep As Geometry.Brep = Brep.Brep
            Dim DefCurve As Geometry.Curve = Curve.Curve

            Dim ProjCrv As Geometry.Curve() = Geometry.Curve.ProjectToBrep(DefCurve, DefBrep, New Geometry.Vector3d(0, 0, 1), doc.ModelAbsoluteTolerance)

            For Each crv In ProjCrv
                doc.Objects.AddCurve(crv)
            Next

            doc.Views.Redraw()

            Return Result.Success
        End Function
    End Class
End Namespace

Ha, I just beat you to it :smile:

@menno noooooooooooo!!

I did learn something new though:

Vector3d.YAxis

Ups, I’ve post up.

The brep is created importing this model

I’ve created a brep model from this contourn and get the faces

I’ve selected the side that I’ve the problem. This face is created with two lines, the selected and the small line below

Hi,

I solve it.

The projection must be:

curvas = Curve.ProjectToBrep(_linea, Face, Plane.WorldYZ.Normal, 1);

I’ve chaged the plane.

I don’t know why in the other plane I get these curve projection, but it’s not important now