AnsweredAssumed Answered

Plot points along ellipse around a point using Lat Long.

Question asked by jmccurry98 on Apr 8, 2016
Latest reply on Apr 11, 2016 by jmccurry98

I am trying to get points to plot along an ellipse around a point. I can get the ellipse to draw but the scale is off (very large). The scale is closer when i divide my variable by "200000".  I believe it has something to do with using lat long (Degrees) instead of x y (Feet). Can anybody check my code/math to see where I'm going wrong? Any advise is appreciated.

____________________

             function drawPt (lat, lon, size, color, drawBorder){

                var markerSymbol = new SimpleMarkerSymbol({ "color": color, "size": size, "type": "esriSMS", "style": "esriSMSCircle", "outline": { "color": [255, 255, 255], "width": 1, "type": "esriSLS", "style": "esriSLSSolid" }});

                if (!drawBorder)

                markerSymbol = new SimpleMarkerSymbol({ "color": color, "size": size, "type": "esriSMS", "style": "esriSMSCircle"});

                var point = new Point({ "x": lon, "y": lat, "spatialReference": {"wkid": 4326 }}),

                markerSymbol = markerSymbol;

                var pointGraphic = new Graphic(point, markerSymbol);

                graphicsLayer.add(pointGraphic);}

 

 

            function toRadians(degrees){

            return degrees * (Math.PI / 180);}

 

 

            function drawEl(lat, lon, major, minor, angle)

            {

                var h = lon; // x coord of ellipse centre (in degrees)

                var k = lat; // y coord of ellipse centre (in degrees)

 

                //The scale is close when i divide these variables by 200000...(= minor/200000)(= major/200000)

                var a = minor; //originally in meters

                var b = major; //originally in meters

 

                var ang = (0-(toRadians(angle))); // rotation, counter-clockwise, from north (I added "0-" to get the additive inverse because 'angle' is a bearing that runs clockwise.)

 

                var points = [];

                for (var i = 0; i < 360; i++) // one point per degree, change if you wish

                 {

                    var t = toRadians(i); // ellipse math

                    var x = a * (Math.cos(t)); // ellipse math

                    var y = b * (Math.sin(t)); // ellipse math

                    var rot_x = h + (x*Math.cos(ang)) - (y * Math.sin(ang)); // rotate/transpose ellipse

                    var rot_y = k + (y*Math.cos(ang)) + (x * Math.sin(ang)); // rotate/transpose ellipse

                    points.push(new Point(rot_x, rot_y)); // save points to list

                    drawPt(rot_y, rot_x, 2, [100, 100, 0], false);

                 }

            }

Outcomes