|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Graphics object to drawHi I need to draw a specific object which consists of a line from a known position and at the end of the line a circle is drawn. The centre of the circle is the end of the line and I want the visible line to be reduced by this radius. On the circle there are also four short lines at the various poles i.e 0 degrees, 90 degrees, 180 degrees and 270 degrees. I had thought about creating either a OMGraphicsList object with each of the components as part of the list. The only thing I need to know is the intersection point of the circle and the line to work out where the actual end of the truncated line will be. Any help would be most appreciated. Thanks in advance. Tony Vasile Senior Software Engineer CSC Level 3B, 26 Talavera Road Macquarie Park NSW 2113 Australia Please consider the environment before printing this e-mail. CSC - This is a private message. If you are not the intended recipient, please delete without copying and kindly advise us by e-mail of the mistake in delivery. Note: Regardless of content, this e-mail shall not operate to bind CSC to any order or other contract unless pursuant to explicit written agreement or government initiative expressly permitting the use of e-mail for such purpose - CSC Australia Pty Limited; Registered Office: 5B/26 Talavera Road, Macquarie Park NSW 2113 Australia; Incorporated in Australia. ACN: 008 476 944 |
||||||||||
|
|
Re: Graphics object to drawHi Tony,
You are on the right track with using an OMGraphicList. I thought this would be easier to figure out, but I ended up adding a method to the GreatCircle class to help with this. If you are using the beta, the code will be updating into the repository shortly. If you are using OpenMap 4.6.5, you can just add this code somewhere: ----------------------------------------------------------- /** * Return a point that is approximately a certain distance along the great * circle line between two points. Returns the nearest coordinate along a * set of calculated segments (as dictated by n) that fits the desired * distance. * * @param phi1 latitude of point 1 in radians. * @param lambda0 longitude of point 1 in radians. * @param phi latitude of point 2 in radians. * @param lambda longitude of point 2 in radians. * @param distance in radians. * @param n number of segments to divide path into. The more segments, the * more accurate. If n <= 0, the OpenMap default of 512 is used. * @return LatLonPoint if distance is less than distance between points, * null if it is greater. */ public LatLonPoint pointAtDistanceBetweenPoints(double phi1, double lambda0, double phi, double lambda, double distance, int n) { LatLonPoint ret = null; double pntDist = GreatCircle.sphericalDistance(phi1, lambda0, phi, lambda); if (pntDist > distance) { if (n <= 0) { n = GeoProj.NUM_DEFAULT_GREAT_SEGS; } double[] gcpoints = GreatCircle.greatCircle(phi1, lambda0, phi, lambda, n, true); // Ratio of desired distance to total distance between points - how // far down the line we need to go. double distRatio = distance / pntDist; // all lat, lon points, get number of vertices, find index of the // one that fits the ratio of the desired distance to the overall // distance between points, and then multiply by 2 to get the actual // index of the matching latitude. int index = (int) ((int) (gcpoints.length / 2) * distRatio) * 2; ret = new LatLonPoint.Double(gcpoints[index], gcpoints [index + 1], true); } return ret; } ----------------------------------------------------------- Then, I just did this to create the OMLine/Circles in DemoLayer: ----------------------------------------------------------- OMGraphicList geoTest = new OMGraphicList(); LatLonPoint pnt1 = new LatLonPoint.Double(42.0, -71.0); LatLonPoint pnt2 = new LatLonPoint.Double(42.3, -70.678); double gspacing = Length.MILE.toRadians(5); OMCircle ompoint1 = new OMCircle(pnt1.getLatitude(), pnt1.getLongitude(), gspacing, Length.RADIAN); OMCircle ompoint2 = new OMCircle(pnt2.getLatitude(), pnt2.getLongitude(), gspacing, Length.RADIAN); LatLonPoint int1 = GreatCircle.pointAtDistanceBetweenPoints (pnt1.getRadLat(), pnt1.getRadLon(), pnt2.getRadLat(), pnt2.getRadLon(), gspacing, -1); LatLonPoint int2 = GreatCircle.pointAtDistanceBetweenPoints (pnt2.getRadLat(), pnt2.getRadLon(), pnt1.getRadLat(), pnt1.getRadLon(), gspacing, -1); OMLine geoline = new OMLine(int1.getLatitude(), int1.getLongitude(), int2.getLatitude(), int2.getLongitude(), OMGraphic.LINETYPE_GREATCIRCLE); ompoint1.setLinePaint(Color.red); ompoint2.setLinePaint(Color.red); geoline.setLinePaint(Color.red); geoTest.add(ompoint1); geoTest.add(ompoint2); geoTest.add(geoline); logger.info("adding geoTest"); omList.add(geoTest); ----------------------------------------------------------- Hope this helps, - Don On Sep 15, 2009, at 4:17 AM, Tony Vasile wrote: > > Hi > > I need to draw a specific object which consists of a line from a > known position and at the end of the line a circle is drawn. The > centre of the circle is the end of the line and I want the visible > line to be reduced by this radius. On the circle there are also four > short lines at the various poles i.e 0 degrees, 90 degrees, 180 > degrees and 270 degrees. I had thought about creating either a > OMGraphicsList object with each of the components as part of the list. > > The only thing I need to know is the intersection point of the > circle and the line to work out where the actual end of the > truncated line will be. > > Any help would be most appreciated. Thanks in advance. > > Tony Vasile > Senior Software Engineer > CSC > > Level 3B, 26 Talavera Road Macquarie Park NSW 2113 Australia > > > Please consider the environment before printing this e-mail. > > CSC - This is a private message. If you are not the intended > recipient, please delete without copying and kindly advise us by e- > mail of the mistake in delivery. Note: Regardless of content, this > e-mail shall not operate to bind CSC to any order or other contract > unless pursuant to explicit written agreement or government > initiative expressly permitting the use of e-mail for such purpose - > CSC Australia Pty Limited; Registered Office: 5B/26 Talavera Road, > Macquarie Park NSW 2113 Australia; Incorporated in Australia. ACN: > 008 476 944 -- [To unsubscribe to this list send an email to "majdart@..." with the following text in the BODY of the message "unsubscribe openmap-users"] |
||||||||||
|
|
Re: Graphics object to drawHi Don, I have included the below code in my code but one thing I notice now is that after going from 4.5.4 to 4.6.5 that I have to explicitly create a LayerHandler for my Canvas object which extends BasicMapPanel . Also my layer which I add to this object via a call to the object's MapHandler.add method it seems that the only layer present is the one I add via the compiled code rather than the graticule layer which I specify in my openmap.properties file and my layer. One other thing is that the background on my layer used to be black and now it is grey. I don't have any explicit calls to set the background of my layer. Any help would be most appreciated. Tony Vasile Senior Software Engineer CSC Level 3B, 26 Talavera Road Macquarie Park NSW 2113 Australia GBS | p: +61 2 9034 2404 | f: +61 2 9034 2404 | avasile@... | www.csc.com Please consider the environment before printing this e-mail. CSC - This is a private message. If you are not the intended recipient, please delete without copying and kindly advise us by e-mail of the mistake in delivery. Note: Regardless of content, this e-mail shall not operate to bind CSC to any order or other contract unless pursuant to explicit written agreement or government initiative expressly permitting the use of e-mail for such purpose - CSC Australia Pty Limited; Registered Office: 5B/26 Talavera Road, Macquarie Park NSW 2113 Australia; Incorporated in Australia. ACN: 008 476 944
Hi Tony, You are on the right track with using an OMGraphicList. I thought this would be easier to figure out, but I ended up adding a method to the GreatCircle class to help with this. If you are using the beta, the code will be updating into the repository shortly. If you are using OpenMap 4.6.5, you can just add this code somewhere: ----------------------------------------------------------- /** * Return a point that is approximately a certain distance along the great * circle line between two points. Returns the nearest coordinate along a * set of calculated segments (as dictated by n) that fits the desired * distance. * * @param phi1 latitude of point 1 in radians. * @param lambda0 longitude of point 1 in radians. * @param phi latitude of point 2 in radians. * @param lambda longitude of point 2 in radians. * @param distance in radians. * @param n number of segments to divide path into. The more segments, the * more accurate. If n <= 0, the OpenMap default of 512 is used. * @return LatLonPoint if distance is less than distance between points, * null if it is greater. */ public LatLonPoint pointAtDistanceBetweenPoints(double phi1, double lambda0, double phi, double lambda, double distance, int n) { LatLonPoint ret = null; double pntDist = GreatCircle.sphericalDistance(phi1, lambda0, phi, lambda); if (pntDist > distance) { if (n <= 0) { n = GeoProj.NUM_DEFAULT_GREAT_SEGS; } double[] gcpoints = GreatCircle.greatCircle(phi1, lambda0, phi, lambda, n, true); // Ratio of desired distance to total distance between points - how // far down the line we need to go. double distRatio = distance / pntDist; // all lat, lon points, get number of vertices, find index of the // one that fits the ratio of the desired distance to the overall // distance between points, and then multiply by 2 to get the actual // index of the matching latitude. int index = (int) ((int) (gcpoints.length / 2) * distRatio) * 2; ret = new LatLonPoint.Double(gcpoints[index], gcpoints [index + 1], true); } return ret; } ----------------------------------------------------------- Then, I just did this to create the OMLine/Circles in DemoLayer: ----------------------------------------------------------- OMGraphicList geoTest = new OMGraphicList(); LatLonPoint pnt1 = new LatLonPoint.Double(42.0, -71.0); LatLonPoint pnt2 = new LatLonPoint.Double(42.3, -70.678); double gspacing = Length.MILE.toRadians(5); OMCircle ompoint1 = new OMCircle(pnt1.getLatitude(), pnt1.getLongitude(), gspacing, Length.RADIAN); OMCircle ompoint2 = new OMCircle(pnt2.getLatitude(), pnt2.getLongitude(), gspacing, Length.RADIAN); LatLonPoint int1 = GreatCircle.pointAtDistanceBetweenPoints (pnt1.getRadLat(), pnt1.getRadLon(), pnt2.getRadLat(), pnt2.getRadLon(), gspacing, -1); LatLonPoint int2 = GreatCircle.pointAtDistanceBetweenPoints (pnt2.getRadLat(), pnt2.getRadLon(), pnt1.getRadLat(), pnt1.getRadLon(), gspacing, -1); OMLine geoline = new OMLine(int1.getLatitude(), int1.getLongitude(), int2.getLatitude(), int2.getLongitude(), OMGraphic.LINETYPE_GREATCIRCLE); ompoint1.setLinePaint(Color.red); ompoint2.setLinePaint(Color.red); geoline.setLinePaint(Color.red); geoTest.add(ompoint1); geoTest.add(ompoint2); geoTest.add(geoline); logger.info("adding geoTest"); omList.add(geoTest); ----------------------------------------------------------- Hope this helps, - Don On Sep 15, 2009, at 4:17 AM, Tony Vasile wrote: > > Hi > > I need to draw a specific object which consists of a line from a > known position and at the end of the line a circle is drawn. The > centre of the circle is the end of the line and I want the visible > line to be reduced by this radius. On the circle there are also four > short lines at the various poles i.e 0 degrees, 90 degrees, 180 > degrees and 270 degrees. I had thought about creating either a > OMGraphicsList object with each of the components as part of the list. > > The only thing I need to know is the intersection point of the > circle and the line to work out where the actual end of the > truncated line will be. > > Any help would be most appreciated. Thanks in advance. > > Tony Vasile > Senior Software Engineer > CSC > > Level 3B, 26 Talavera Road Macquarie Park NSW 2113 Australia > > > Please consider the environment before printing this e-mail. > > CSC - This is a private message. If you are not the intended > recipient, please delete without copying and kindly advise us by e- > mail of the mistake in delivery. Note: Regardless of content, this > e-mail shall not operate to bind CSC to any order or other contract > unless pursuant to explicit written agreement or government > initiative expressly permitting the use of e-mail for such purpose - > CSC Australia Pty Limited; Registered Office: 5B/26 Talavera Road, > Macquarie Park NSW 2113 Australia; Incorporated in Australia. ACN: > 008 476 944 |
||||||||||
|
|
|
||||||||||
|
|
Re: Re: Graphics object to drawHi Tony,
I'm not sure what you mean by radians in the projected world if you aren't talking about angles. You can't have a fixed size circle defined with a radian-based radius. Or are you looking for an arc, or wedge? - Don Tony Vasile wrote: > > So I have my shape with the line drawn to the circle and the lines > sticking out of it but I want to have a fixed size circle so I created > with OMCircle(lat, lon, 20, 20) so I get a 20 pixel circle. Now is > there any way to go from the radius in pixels to a value in radians. I > assume I need something from the projection which converts between x/y > values and radians in the projected world. > > Tony Vasile > Senior Software Engineer > CSC > > Level 3B, 26 Talavera Road Macquarie Park NSW 2113 Australia > GBS | p: +61 2 9034 2404 | f: +61 2 9034 2404 | avasile@... | > www.csc.com > > > Please consider the environment before printing this e-mail. > > CSC - This is a private message. If you are not the intended > recipient, please delete without copying and kindly advise us by > e-mail of the mistake in delivery. Note: Regardless of content, this > e-mail shall not operate to bind CSC to any order or other contract > unless pursuant to explicit written agreement or government initiative > expressly permitting the use of e-mail for such purpose - CSC > Australia Pty Limited; Registered Office: 5B/26 Talavera Road, > Macquarie Park NSW 2113 Australia; Incorporated in Australia. ACN: 008 > 476 944 -- [To unsubscribe to this list send an email to "majdart@..." with the following text in the BODY of the message "unsubscribe openmap-users"] |
||||||||||
|
|
Re: Re: Graphics object to drawHi Don, The algorithm that you sent me which calculates the intersection point of the line and the circle requires a distance in radians for the radius of the circle. What I have is a fixed 20 pixel (width and height) circle which I need to know the radius in radians to pass to the pointAtDistanceBetweenPoints method. That is why I need to convert from pixels to radians based on the current projection settings. Tony Vasile Senior Software Engineer CSC Level 3B, 26 Talavera Road Macquarie Park NSW 2113 Australia GBS | p: +61 2 9034 2404 | f: +61 2 9034 2404 | avasile@... | www.csc.com Please consider the environment before printing this e-mail. CSC - This is a private message. If you are not the intended recipient, please delete without copying and kindly advise us by e-mail of the mistake in delivery. Note: Regardless of content, this e-mail shall not operate to bind CSC to any order or other contract unless pursuant to explicit written agreement or government initiative expressly permitting the use of e-mail for such purpose - CSC Australia Pty Limited; Registered Office: 5B/26 Talavera Road, Macquarie Park NSW 2113 Australia; Incorporated in Australia. ACN: 008 476 944
Hi Tony, I'm not sure what you mean by radians in the projected world if you aren't talking about angles. You can't have a fixed size circle defined with a radian-based radius. Or are you looking for an arc, or wedge? - Don Tony Vasile wrote: > > So I have my shape with the line drawn to the circle and the lines > sticking out of it but I want to have a fixed size circle so I created > with OMCircle(lat, lon, 20, 20) so I get a 20 pixel circle. Now is > there any way to go from the radius in pixels to a value in radians. I > assume I need something from the projection which converts between x/y > values and radians in the projected world. > > Tony Vasile > Senior Software Engineer > CSC > > Level 3B, 26 Talavera Road Macquarie Park NSW 2113 Australia > GBS | p: +61 2 9034 2404 | f: +61 2 9034 2404 | avasile@... | > www.csc.com > > > Please consider the environment before printing this e-mail. > > CSC - This is a private message. If you are not the intended > recipient, please delete without copying and kindly advise us by > e-mail of the mistake in delivery. Note: Regardless of content, this > e-mail shall not operate to bind CSC to any order or other contract > unless pursuant to explicit written agreement or government initiative > expressly permitting the use of e-mail for such purpose - CSC > Australia Pty Limited; Registered Office: 5B/26 Talavera Road, > Macquarie Park NSW 2113 Australia; Incorporated in Australia. ACN: 008 > 476 944 |
| Free embeddable forum powered by Nabble | Forum Help |