From: <emm...@us...> - 2008-09-25 15:13:29
|
Revision: 3981 http://fudaa.svn.sourceforge.net/fudaa/?rev=3981&view=rev Author: emmanuel_martin Date: 2008-09-25 15:13:21 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Ajout de la projection d'un point sur un plan et de son teste. Modified Paths: -------------- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISLib.java branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/test/org/fudaa/ctulu/gis/TestJGIS.java Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISLib.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISLib.java 2008-09-25 13:34:36 UTC (rev 3980) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/src/org/fudaa/ctulu/gis/GISLib.java 2008-09-25 15:13:21 UTC (rev 3981) @@ -9,6 +9,10 @@ import java.util.List; +import org.fudaa.ctulu.CtuluLibGeometrie; +import org.fudaa.ctulu.ProgressionInterface; +import org.fudaa.ctulu.ProgressionUpdater; +import org.fudaa.ctulu.gui.CtuluValueEditorDefaults; import org.geotools.feature.AttributeType; import com.vividsolutions.jts.algorithm.CGAlgorithms; @@ -22,11 +26,6 @@ import com.vividsolutions.jts.geom.LineString; import com.vividsolutions.jts.geom.LinearRing; -import org.fudaa.ctulu.CtuluLibGeometrie; -import org.fudaa.ctulu.ProgressionInterface; -import org.fudaa.ctulu.ProgressionUpdater; -import org.fudaa.ctulu.gui.CtuluValueEditorDefaults; - /** * @author deniger * @version $Id$ @@ -388,7 +387,38 @@ * @return LE point 3D sur le plan de projection. */ public static GISPoint projectOnPlane(GISPoint[] _plan, GISPoint _pt) { - return null; + // Teste si on a toute les donn\xE9es + if (_plan==null||_pt==null||_plan.length<3||_plan[0]==null||_plan[1]==null||_plan[2]==null) + return null; + // On nomme : a, b, c les trois points d\xE9finissant le plan + double xa=_plan[0].getX(), ya=_plan[0].getY(), za=_plan[0].getZ(), + xb=_plan[1].getX(), yb=_plan[1].getY(), zb=_plan[1].getZ(), + xc=_plan[2].getX(), yc=_plan[2].getY(), zc=_plan[2].getZ(); + // Teste que les trois points d\xE9finissant le plan sont diff\xE9rents + if ((xa==xb&&ya==yb&&za==zb)||(xb==xc&&yb==yc&&zb==zc)||(xa==xc&&ya==yc&&za==zc)) + return null; + // On nomme : i le point \xE0 projeter ; p le point projet\xE9. + double xi=_pt.getX(), yi=_pt.getY(), zi=_pt.getZ(), + xp, yp, zp; + // Calcul du vecteur ab nomm\xE9 v + double xv = xb - xa, + yv = yb - ya, + zv = zb - za; + // Calcul du vecteur ac nomm\xE9 u + double xu = xc - xa, + yu = yc - ya, + zu = zc - za; + // Calcul du vecteur w d\xE9fini comme le produit vectoriel entre v et u + double xw = yu*zv - zu*yv, + yw = zu*xv - xu*zv, + zw = xu*yv - yu*xv; + // On calcul k qui est d\xE9fini tel que : vecteur(ip) = k * w + double k = ((xa+xi)*xw+(ya+yi)*yw+(za+zi)*zw)/(xw*xw+yw*yw+zw*zw); + // Calcul des coordonn\xE9es de p + xp = xi + k*xw; + yp = yi + k*yw; + zp = zi + k*zw; + return new GISPoint(xp, yp, zp); } public static Envelope computeEnveloppe(final GISDataModel[] _models, final ProgressionInterface _prog) { Modified: branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/test/org/fudaa/ctulu/gis/TestJGIS.java =================================================================== --- branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/test/org/fudaa/ctulu/gis/TestJGIS.java 2008-09-25 13:34:36 UTC (rev 3980) +++ branches/FudaaModeleur_TC1Bis/fudaa_devel/ctulu/test/org/fudaa/ctulu/gis/TestJGIS.java 2008-09-25 15:13:21 UTC (rev 3981) @@ -14,16 +14,15 @@ import junit.framework.TestCase; +import org.fudaa.ctulu.CtuluCommandComposite; +import org.fudaa.ctulu.CtuluLibString; +import org.fudaa.ctulu.gis.mif.MIFStringTokenizer; + import com.vividsolutions.jts.algorithm.NonRobustLineIntersector; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.LinearRing; import com.vividsolutions.jts.geom.Polygon; -import org.fudaa.ctulu.CtuluCommandComposite; -import org.fudaa.ctulu.CtuluLibString; -import org.fudaa.ctulu.gis.mif.MIFFileTokenizer; -import org.fudaa.ctulu.gis.mif.MIFStringTokenizer; - /** * @author Fred Deniger * @version $Id: TestJGIS.java,v 1.6 2007-05-21 10:28:31 deniger Exp $ @@ -34,6 +33,24 @@ } + public void testProjectOnPlane(){ + // Cas g\xE9n\xE9ral + GISPoint[] plan = {new GISPoint(1, 0, 0), new GISPoint(0, 1, 0), new GISPoint(0, 0, 1)}; + GISPoint result = GISLib.projectOnPlane(plan, new GISPoint(0, 0, 0)); + assertEquals(result.getX(), 1/3., 0.0000001); + assertEquals(result.getY(), 1/3., 0.0000001); + assertEquals(result.getZ(), 1/3., 0.0000001); + // Test de robustesse : valeur null + assertNull(GISLib.projectOnPlane(null, new GISPoint(0, 0, 0))); + assertNull(GISLib.projectOnPlane(plan, null)); + plan[1] = null; + assertNull(GISLib.projectOnPlane(plan, new GISPoint(0, 0, 0))); + // Test de robustesse : plan mal d\xE9fini + plan[1] = plan[0]; + assertNull(GISLib.projectOnPlane(plan, new GISPoint(0, 0, 0))); + GISPoint[] plan2 = {new GISPoint(0, 1, 0), new GISPoint(0, 0, 1)}; + assertNull(GISLib.projectOnPlane(plan2, new GISPoint(0, 0, 0))); + } public void testLTrim(){ assertEquals("", MIFStringTokenizer.ltrim("\t\t")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |