Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6ABE34AB7 for ; Tue, 5 Jul 2011 20:07:24 +0000 (UTC) Received: (qmail 71375 invoked by uid 500); 5 Jul 2011 20:07:23 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 71264 invoked by uid 500); 5 Jul 2011 20:07:22 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 71253 invoked by uid 99); 5 Jul 2011 20:07:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jul 2011 20:07:22 +0000 X-ASF-Spam-Status: No, hits=1.8 required=5.0 tests=FREEMAIL_FROM,HTML_FONT_FACE_BAD,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of curtis.jensen@gmail.com designates 209.85.212.43 as permitted sender) Received: from [209.85.212.43] (HELO mail-vw0-f43.google.com) (209.85.212.43) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jul 2011 20:07:15 +0000 Received: by vws10 with SMTP id 10so5434522vws.30 for ; Tue, 05 Jul 2011 13:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=v8dub68Rg97Guf2LBr3k5AzLvWOM8vquRjd8XhXoUuY=; b=otnertSHzi8wE/5Uafch6icus9YavULbFwLAJO5Q5uYjRdjk+yX3cnQYyrJJMrFwW3 fgamMOkzyX5jIhyH4ylZueD5fNEoPWntNYs8L8L/ClEvQiuOpv5MeAwgFxCqS3Khd0Gn boIjmBWpvl6A52utzXL7wrSBPOvDshYCqqYkk= MIME-Version: 1.0 Received: by 10.52.160.40 with SMTP id xh8mr4754463vdb.199.1309896414116; Tue, 05 Jul 2011 13:06:54 -0700 (PDT) Sender: curtis.jensen@gmail.com Received: by 10.52.107.162 with HTTP; Tue, 5 Jul 2011 13:06:54 -0700 (PDT) In-Reply-To: References: Date: Tue, 5 Jul 2011 13:06:54 -0700 X-Google-Sender-Auth: ZBILMXo59aMlT4GnUgi2F45SMso Message-ID: Subject: Re: [math] Polygon intersection vertices outside original polygon From: Curtis Jensen To: Commons Users List Content-Type: multipart/alternative; boundary=bcaec53f946774bbce04a758064a X-Virus-Checked: Checked by ClamAV on apache.org --bcaec53f946774bbce04a758064a Content-Type: text/plain; charset=UTF-8 On Mon, Jul 4, 2011 at 2:00 PM, Curtis Jensen wrote: > I'm using the RegonFactory.intersection method to get the intersection of > polygons. However, I'm getting points that are outside of one of the > original polygons. See example below. Am I misinterpreting what the > intersection method does, miss-using it, or is this a bug? > > > Vector2D[][] vertices1 = new Vector2D[][] { > new Vector2D[] { > new Vector2D(-25.8907, 53.6079), > new Vector2D(-25.3586, 53.5214), > new Vector2D(-25.6256, 53.1507), > new Vector2D(-26.0395, 53.2562) > } > }; > PolygonsSet set1 = buildSet(vertices1); > Vector2D[][] vertices2 = new Vector2D[][] { > new Vector2D[] { > new Vector2D(-25.7455, 53.3656), > new Vector2D(-25.3007, 53.2765), > new Vector2D(-25.4181, 52.9993), > new Vector2D(-25.9476, 53.0366) > } > }; > PolygonsSet set2 = buildSet(vertices2); > PolygonsSet intersectionSet = (PolygonsSet) new > RegionFactory().intersection(set1.copySelf(), set2.copySelf()); > > Vector2D[][] intersectionVerts = intersectionSet.getVertices(); > for (Vector2D[] set : intersectionVerts) { > for (Vector2D vertex : set) { > System.out.println(vertex); > } > } > > > OUTPUT: > {-26.04; 53.26} > {-25.89; 53.61} > {-25.36; 53.52} > {-25.51; 53.32} > {-25.3; 53.28} > {-25.42; 53} <- OUTSIDE polygon A > {-25.72; 53.02} <- OUTSIDE polygon A > {-25.95; 53.04} <- OUTSIDE polygon A > {-25.84; 53.21} > I should add that the buildSet function is the same as that in the test suit of commons math: private PolygonsSet buildSet(Vector2D[][] vertices) { ArrayList> edges = new ArrayList>(); for (int i = 0; i < vertices.length; ++i) { int l = vertices[i].length; for (int j = 0; j < l; ++j) { edges.add(buildSegment(vertices[i][j], vertices[i][(j + 1) % l])); } } return new PolygonsSet(edges); } --bcaec53f946774bbce04a758064a--