Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:11:11+00:00 2026-06-18T00:11:11+00:00

I have this code here to find out if a line is in a

  • 0

I have this code here to find out if a line is in a circle. (Maybe you can use this to base your answer on)

/**
*@param l1  Line point 1, containing latitude and longitude
*@param l2  Line point 2, containing latitude and longitude
*@param c   Center of circle, containing latitude and longitud
*@param r   Radius of the circle
**/
Maps.ui.inCircle = function(l1, l2, c, r){
    var a = l1.lat() - l2.lat()
    var b = l1.lng() - l2.lng()
    var x = Math.sqrt(a*a + b*b)
    return (Math.abs((c.lat() - l1.lat()) * (l2.lng() - l1.lng()) - (c.lng() - l1.lng()) * (l2.lat() - l1.lat())) / x <= r);
}

This works perfectly for that. But now I need to find out if a point is in the area around a line. For example, the blue dots in this would return true, and the purple lines I would return true. But not the green lines or dots. Also I need to find out whether a line cuts through the line.

enter image description here

Here is my code to see if a line intersects this line:

function getLineIntersaction(y1,x1,y2,x2, y3,x3,y4,x4){
    if (Math.max(X1,X2) < Math.min(X3,X4)) // This means no same coordinates
        return false;  
    m1 = (y1-y2)/(x1-x2); 
    m2 = (y3-y4)/(x3-x4); 
    c1 = y1-m1x1; 
    c2 = y3-m2x3; 
    if(m1=m2)//segments are parallel.
        return false;
    var x = (c1-c2)/(m2-m1); 
    if(!isNaN(x) && isFinite(x)){
        if( x < Math.max(Math.min(x1,x2),math.min(x3,x4)) || x > Math.min(Math.max(x1,x2),Math.max(x3,x4)))
            return false;
        else
            return true;
    }
    return false;
}

So this needs to be integrated in with the other code.

How can I do this? I could pass the function a line or I could pass it just a single point.

If a line is passed then we will run the above function. I want it to return an array. The first item in the array will return if it is near it (in the red area) and the second item in the array will return if the segment cuts the line. Meaning if it is just a point then the second item will always be false.

QUESTION

How can I tell if a line or point lays within the red area?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:11:12+00:00Added an answer on June 18, 2026 at 12:11 am

    Quoting my answer to this question

    The first step is to find the normal projection of the point onto the line. This is actually quite simple: take the distance from point 1 to the target, and point 2 to the target, and call them D1 and D2 respectively. Then calculate D1+(D2-D1)/2. This is the distance to the projected point on the line from point 1.

    You can now find that point, and get the distance from that point to the target. If the distance is zero, then the target is exactly on the line. If the distance is less than 5, then the target was less than 5px away, and so on.

    EDIT: A picture is worth a thousand words. Here’s a diagram:

    Diagram
    (source: adamhaskell.net)

    (In hindsight, probably should have made those circles a different colour… Also, the purple line is supposed to be perpendicular to line AB. Blame my terrible aim with the blue line!)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's wrong with this set of code? I have errors and I can't find
I have this code here printf '$request1 = select * from whatever where this
I have this code here, which is intended to allow any type of arguments:
I have this code here, {foreach from=$cart.cartItems item=item name=cart} <div id=cart2Produkt> <p>{if $item.Product.ID} <a
I have this code here: var Person = (function() { var name; var PersonConstructor
So I have this code here: <table> <tr> <td width=200px valign=top> <div class=left_menu> <div
i have this quick issue please. I have this code here which permits me
I have this code down here. When format.js fires I want to serve to
I have this code right here, where the $friends variable is an array with
i have this code right here: <select name=group> <option value=>Choose a group....</option> <?php foreach($groups

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.