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 1006191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:25:07+00:00 2026-05-16T08:25:07+00:00

I’m trying to do some advanced features with android maps and to do that

  • 0

I’m trying to do some advanced features with android maps and to do that I need to do some operations on vectors. Now – I read the answer from this and it gave me some hints and tips. However, there is a part which I don’t understand. Please allow me to quote this:

Now that we have the ray with its start and end coordinates, the problem shifts from “is the point within the polygon” to “how often intersects the ray a polygon side”. Therefor we can’t just work with the polygon points as before (for the bounding box), now we need the actual sides. A side is always defined by two points.

side 1: (X1/Y1)-(X2/Y2) side 2:
(X2/Y2)-(X3/Y3) side 3:
(X3/Y3)-(X4/Y4)

So my understanding is that every side of the triangle is actually a vector. But how is it possible to substract 2 points? Let’s say I got a triangle with 3 vertices: A(1,1) , B(2,2), C (1,3). So according to that, I have to do, for example, (1,1)-(2,2) in order to calculate one of the sides. The question is how to do it programatically in java/android? Below I’m attaching the code which I already developed:

    /** Creating the containers for screen 
     *  coordinates taken from geoPoints
     */

    Point point1_screen = new Point();
    Point point2_screen = new Point();
    Point point3_screen = new Point();

    /* Project them from the map to screen */
    mapView.getProjection().toPixels(point1, point1_screen);
    mapView.getProjection().toPixels(point2, point2_screen);
mapView.getProjection().toPixels(point3, point3_screen);

    int xA = point1_screen.x;
    int yA = point1_screen.y;

    int xB = point2_screen.x;
    int yB = point2_screen.y;

    int xC = point3_screen.x;
    int yC = point3_screen.y;

    int[] xPointsArray = new int[3];
    int[] yPointsArray = new int[3];

    xPointsArray[0] = xA;
    xPointsArray[1] = xB;
    xPointsArray[2] = xC;

    yPointsArray[0] = yA;
    yPointsArray[1] = yB;
    yPointsArray[2] = yC;

    Arrays.sort(xPointsArray);

    int xMin = xPointsArray[0];
    int yMin = yPointsArray[0];

    int xMax = xPointsArray[xPointsArray.length-1];
    int yMax = xPointsArray[xPointsArray.length-1]; 

    int e = (xMax - xMin) / 100;                                    // for ray calcultions

    int width = mapView.getWidth();
    int height = mapView.getHeight();

    if(pPoint.x < xMin || pPoint.x > xMax || pPoint.y > yMin || pPoint.y < yMax)
    {

        DisplayInfoMessage(pPoint.x + " < " + xMin + " AND "  + pPoint.x + " > " + xMax + " || " + pPoint.y + " < " + yMin + " AND "  + pPoint.y + " > " + yMax );
    //  DisplayInfoMessage("Minimum is: "+  yPointsArray[0] + " and the maximum is: "+ yPointsArray[xPointsArray.length-1]);

    }
    else
    {
         GeoPoint start_point = new GeoPoint(xMin - e, pPoint.y);
         Point start_point_container = new Point();  
         mapView.getProjection().toPixels(start_point, start_point_container);

            int a, b, c, tx, ty;
            int d1, d2, hd;
            int ix, iy;
            float r;
            // calculating vector for 1st line

            tx = xB - xA;
            ty = yB - yA;

            // equation for 1st line

            a = ty;
            b = tx;
            c = xA*a - yA*b;

            // get distances from line for line 2

            d1 = a*xB + b*yB + c;
            d2 = a*pPoint.x + b*pPoint.y + c;



            DisplayInfoMessage("You clicked inside the triangle!" + "TRIANGLE POINTS: A("+xA+","+yA+") B("+xB+","+yB+") C("+xC+","+yC+")");
    }

The pPoint hold the coordinates of the point which user clicked. I hope that I explained my problem well enough. Can someone give me some help with that? Appreciated!

  • 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-05-16T08:25:08+00:00Added an answer on May 16, 2026 at 8:25 am

    I’m not an Android developer, but I see that android.graphics.drawable.shapes.Shape lacks the contains() method found in java.awt.Shape. It appears you’ll have to develop your own test, as suggested in the article you cited. In addition, you might want to look at crossing/winding number algorithms.

    But how is it possible to subtract 2 points?

    Subtraction of vectors is well defined, and easily implemented in Java. Given two points as vectors, the components of the difference represent the tangent (slope) of a line connecting the points. The example in the article implements this in the following lines:

    //get tangent vector for line 1
    tx = v1x2 - v1x1;
    ty = v1y2 - v1y1;
    

    The foundation for the approach shown is discussed further in Line and Segment Intersections.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.