Select to view content in your preferred language

Plot points along ellipse around a point using Lat Long.

3072
3
Jump to solution
04-08-2016 01:32 PM
JoshuaMcCurry
Occasional Contributor

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);

                 }

            }

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

I dont suppose you have access to pointFromAngleAndDistance (angle, distance, {method}) like we do with arcpy in arcmap

PointGeometry—Help | ArcGIS for Desktop

in any event, you could use projected coordinate for the origin, calculate your new locations using planar values for distance and angle, then project back to geographic

View solution in original post

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

I dont suppose you have access to pointFromAngleAndDistance (angle, distance, {method}) like we do with arcpy in arcmap

PointGeometry—Help | ArcGIS for Desktop

in any event, you could use projected coordinate for the origin, calculate your new locations using planar values for distance and angle, then project back to geographic

0 Kudos
JoshuaMcCurry
Occasional Contributor

Thanks Dan,

I only have access to what is available through the Javascript API. I think that the code is drawing the points along the ellipse correctly, but, tying the math in with the projection/scaling issue is what I'm having trouble with.

Josh

0 Kudos
JoshuaMcCurry
Occasional Contributor

Dan,

You were right, re-projecting the coordinates and doing the calculations on planar values worked. The math above is right, I just cant use lat/longs. Thanks again!

0 Kudos