help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: point projection on polyline


From: Juan Pablo Carbajal
Subject: Re: point projection on polyline
Date: Sat, 21 Nov 2015 12:47:41 +0100

On Sat, Nov 21, 2015 at 4:52 AM, rcharan51 <address@hidden> wrote:
> Yes, I have a polyline with some 700 vertices and I want to find projection
> of points(grid of (x,y) points that contains the polyline) that are
> <80units away from the polyline. So, I first calculated the distance of all
> points in grid then I called "projpointonpolyline" in a for loop only for
> those points that have distpointedge<80 (which turns out to be some 7000
> points). That 'for' loop takes 15-20min to complete.
>
> Best Regards,
>
> Raghu Charan A,
>
> B. Tech (Hons) Civil Engineering (class of 2015),
>
> School of Infrastructure,IIT Bhubaneswar, India.
>
> Email: address@hidden, address@hidden
> Mobile No: +91 8860567691, +91 7205733924
>
>
> On Fri, Nov 20, 2015 at 11:22 PM, Juan Pablo Carbajal-2 [via Octave] <
> address@hidden> wrote:
>
>> On Fri, Nov 20, 2015 at 11:02 AM, rcharan51 <[hidden email]
>> <http:///user/SendEmail.jtp?type=node&node=4673588&i=0>> wrote:
>>
>> > and sorry(I almost forgot) here's the code on bpaste
>> >
>> > https://bpaste.net/show/dc93ef0c7e20
>> >
>> > Best Regards,
>> >
>> > Raghu Charan A,
>> >
>> > B. Tech (Hons) Civil Engineering (class of 2015),
>> >
>> > School of Infrastructure,IIT Bhubaneswar, India.
>> >
>> > Email: [hidden email]
>> <http:///user/SendEmail.jtp?type=node&node=4673588&i=1>, [hidden email]
>> <http:///user/SendEmail.jtp?type=node&node=4673588&i=2>
>> > Mobile No: +91 8860567691, +91 7205733924
>> >
>> >
>> > On Fri, Nov 20, 2015 at 11:35 AM, Raghu Charan A <[hidden email]
>> <http:///user/SendEmail.jtp?type=node&node=4673588&i=3>> wrote:
>> >
>> >> No need to thank it's mutual. Congratulations !!
>> >> BTW whom do you support in the clasico?
>> >> On Nov 17, 2015 17:40, "Juan Pablo Carbajal-2 [via Octave]" <
>> >> [hidden email] <http:///user/SendEmail.jtp?type=node&node=4673588&i=4>>
>> wrote:
>> >>
>> >>> On Tue, Nov 17, 2015 at 6:44 AM, rcharan51 <[hidden email]
>> >>> <http:///user/SendEmail.jtp?type=node&node=4673532&i=0>> wrote:
>> >>>
>> >>> > Is there any alternative without calling distancePointEdge inside
>> >>> > projectPointOnPolyline, which I beleive is the main reason for slow
>> >>> running
>> >>> > of the function. I could not understand the algorithm but I found a
>> >>> similar
>> >>> > function in Scilab. here's the source code for it
>> >>> > https://searchcode.com/codesearch/view/25401835/
>> >>> >
>> >>> >
>> >>> >
>> >>> > --
>> >>> > View this message in context:
>> >>>
>> http://octave.1599824.n4.nabble.com/point-projection-on-polyline-tp4673298p4673526.html
>> >>> > Sent from the Octave - General mailing list archive at Nabble.com.
>> >>> >
>> >>> > _______________________________________________
>> >>> > Help-octave mailing list
>> >>> > [hidden email] <
>> http:///user/SendEmail.jtp?type=node&node=4673532&i=1>
>> >>> > https://lists.gnu.org/mailman/listinfo/help-octave
>> >>>
>> >>> Hi,
>> >>> Thanks for sending the demos, but I did not get anything. Sometimes
>> >>> the mailing list filters attachments. Better post the code in Gist[1]
>> >>> or in bpaste[2].
>> >>>
>> >>> My daughter was born 4 days ago, so it might be a while till I am able
>> >>> to look into the code, but I will do it asap.
>> >>>
>> >>>
>> >>> [1] https://gist.github.com/
>> >>> [2] https://bpaste.net/
>> >>>
>> >>> _______________________________________________
>> >>> Help-octave mailing list
>> >>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=4673532&i=2>
>>
>> >>> https://lists.gnu.org/mailman/listinfo/help-octave
>> >>>
>> >>>
>> >>> ------------------------------
>> >>> If you reply to this email, your message will be added to the
>> discussion
>> >>> below:
>> >>>
>> >>>
>> http://octave.1599824.n4.nabble.com/point-projection-on-polyline-tp4673298p4673532.html
>> >>> To start a new topic under Octave - General, email
>> >>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=4673588&i=5>
>> >>> To unsubscribe from Octave, click here
>> >>> <
>> >>> .
>> >>> NAML
>> >>> <
>> http://octave.1599824.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>> >>>
>> >>
>> >
>> > --
>> >
>> > ------------------------------
>> > *Disclaimer: *This email and any files transmitted with it are
>> confidential
>> > and intended solely for the use of the individual or entity to whom they
>> > are addressed. If you have received this email in error please notify
>> the
>> > system manager. This message contains confidential information and is
>> > intended only for the individual named. If you are not the named
>> addressee
>> > you should not disseminate, distribute or copy this e-mail. Please
>> notify
>> > the sender immediately by e-mail if you have received this e-mail by
>> > mistake and delete this e-mail from your system. If you are not the
>> > intended recipient you are notified that disclosing, copying,
>> distributing
>> > or taking any action in reliance on the contents of this information is
>> > strictly prohibited.
>> >
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> http://octave.1599824.n4.nabble.com/point-projection-on-polyline-tp4673298p4673580.html
>> > Sent from the Octave - General mailing list archive at Nabble.com.
>> >
>> > _______________________________________________
>> > Help-octave mailing list
>> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4673588&i=6>
>> > https://lists.gnu.org/mailman/listinfo/help-octave
>>
>> Ok, thakns. I had already added  demot that is quite similar to ours.
>> Let me know if you think yours adds soemthing special that I did not
>> noticed.
>> The algorithm of the two functions is the same. You calculate the
>> distance between a given point and all the segments of the polyline.
>> Then you return this distance and the orthogonal projection on that
>> segment. This is brute force search, and there is little else you can
>> do unless you want to implement octrees or another data structure that
>> optimizes the search. The difference between the function you sent and
>> the one in geometry is that the computation of the distance and
>> projection on the edge is encapsulated in the function
>> distancePointEdge. This last function has some optimizations on it
>> that use broadcast instead of looping, but feel free to profile it and
>> check if there is anything to improve.
>>
>> If you port the Scilab function it should perform similarly.
>>
>> What is your problem exactly? Do you have many points and a single
>> polyline or your have a massive polyline and a few points (compared
>> with the number of vertices of the polyline)?
>>
>> If you have many points and a fixed polyline, look at the demo I added
>> to the function. It uses arrayfun and calls the function for each
>> point (this prevents one of the nested loops within the function, and
>> it cloud be improved to do this by default). If your polyline has many
>> segments then I can provide a function that uses arrayfun for the
>> looping of the edges.
>>
>> _______________________________________________
>> Help-octave mailing list
>> [hidden email] <http:///user/SendEmail.jtp?type=node&node=4673588&i=7>
>> https://lists.gnu.org/mailman/listinfo/help-octave
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://octave.1599824.n4.nabble.com/point-projection-on-polyline-tp4673298p4673588.html
>> To start a new topic under Octave - General, email
>> address@hidden
>> To unsubscribe from Octave, click here
>> <http://octave.1599824.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1599824&code=c3JhMTBAaWl0YmJzLmFjLmlufDE1OTk4MjR8MTU5MDQyODc2Mw==>
>> .
>> NAML
>> <http://octave.1599824.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
> --
>
> ------------------------------
> *Disclaimer: *This email and any files transmitted with it are confidential
> and intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify the
> system manager. This message contains confidential information and is
> intended only for the individual named. If you are not the named addressee
> you should not disseminate, distribute or copy this e-mail. Please notify
> the sender immediately by e-mail if you have received this e-mail by
> mistake and delete this e-mail from your system. If you are not the
> intended recipient you are notified that disclosing, copying, distributing
> or taking any action in reliance on the contents of this information is
> strictly prohibited.
>
>
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/point-projection-on-polyline-tp4673298p4673592.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-octave

Please reply at the bottom of the messages, as I am doing here.

Do not use a for loop. Try cellfun or arrayfun, see demo in the online
repository. If you want to use a loop then just pass all the selected
points directly to the function (it loops over the points internally).

Also, if you already calculated the distance tot he polyline you also
already know what is the closest edge, so you do not need
projPointonPolyline at all.

You can also try to do some culling. If you already know that the
points are not farther away from the polyline in more than 80 units,
then calculate the distance to the subsection of the polyline that
falls inside a circle of radius 80 around the point (not the whole
polyline). This will reduce the number of edges you need to compare.

Cheers



reply via email to

[Prev in Thread] Current Thread [Next in Thread]