我正在开发应用程序,我必须在点击上绘制多个固定大小的多边形,例如10 x 25.这样我已成功存档现在我需要以给定角度旋转选定的多边形(让我们考虑0到360)当我点击+按钮时,多边形应该向右旋转并添加1度角,同样点击 - 按钮应该向左旋转多边形任何人都知道如何实现这个?
添加一些代码供考虑。
public void drawPolygonWithGivenDimention(LatLng latLng,float width,float height,float innerDistance,boolean forUpdate,int id)
{
model = new ModelMarker();
model.setId(id);
// Paras Outer Polygon
Location clickedPoint = new Location("clicked");
clickedPoint.setLatitude(latLng.latitude);
clickedPoint.setLongitude(latLng.longitude);
LatLng latLng0 = new LatLng(clickedPoint.getLatitude(), clickedPoint.getLongitude());
pointList.add(latLng0);
Location loc1 = locationForAngle(0.0f, clickedPoint, width);
LatLng latLng1 = new LatLng(loc1.getLatitude(), loc1.getLongitude());
pointList.add(latLng1);
Location loc2 = locationForAngle(90.0f, loc1, height);
LatLng latLng2 = new LatLng(loc2.getLatitude(), loc2.getLongitude());
pointList.add(latLng2);
Location loc3 = locationForAngle(180.0f, loc2, width);
LatLng latLng3 = new LatLng(loc3.getLatitude(), loc3.getLongitude());
pointList.add(latLng3);
model.setPointList(pointList);
// Paras Inner Polygon
Location locPeri = locationForAngle(0.0f,clickedPoint,innerDistance);//Change\
locPeri = locationForAngle(90.0f ,locPeri,innerDistance);
LatLng latLng10 = new LatLng(locPeri.getLatitude(), locPeri.getLongitude());
pointListInner.add(latLng10);
Location loc11 = locationForAngle(0.0f, locPeri, width-innerDistance*2);
LatLng latLng11 = new LatLng(loc11.getLatitude(), loc11.getLongitude());
pointListInner.add(latLng11);
Location loc12 = locationForAngle(90.0f, loc11, height-innerDistance*2);
LatLng latLng12 = new LatLng(loc12.getLatitude(), loc12.getLongitude());
pointListInner.add(latLng12);
Location loc13 = locationForAngle(180.0f, loc12, width-innerDistance*2);
LatLng latLng13 = new LatLng(loc13.getLatitude(), loc13.getLongitude());
pointListInner.add(latLng13);
model.setPointListInner(pointListInner);
drawOuterPolygon(forUpdate);
}
private void drawOuterPolygon(boolean forUpdate)
{
try
{
pointList = model.getPointList();
Polygon poligone;
PolygonOptions polygoneOptions = new PolygonOptions();
polygoneOptions.addAll(pointList);
polygoneOptions.strokeWidth(2);
polygoneOptions.strokeColor(Color.BLACK);
polygoneOptions.fillColor(drawColor);
poligone = googleMap.addPolygon(polygoneOptions);
poligone.setClickable(true);
if(forUpdate)
polygons.set(selectedMarkerPosition,poligone);
else
polygons.add(poligone);
model.setPolygon(poligone);
model.setPolygons(polygons);
drawInnerPolygon(forUpdate);
//getCenterPoint();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public Location locationForAngle(float angle,Location center,float distances)
{
//in Yard 6975174.98 radius of earth
double distanceRadians = distances / 6967410.0; // Yards
//6,371 = Earth's radius in km
double bearingRadians = deg2rad(angle);
double fromLatRadians = deg2rad(center.getLatitude());
double fromLonRadians = deg2rad(center.getLongitude());
double toLatRadians = Math.asin( Math.sin(fromLatRadians) * Math.cos(distanceRadians)+ Math.cos(fromLatRadians) * Math.sin(distanceRadians) * Math.cos(bearingRadians) );
double toLonRadians = fromLonRadians + Math.atan2(Math.sin(bearingRadians) * Math.sin(distanceRadians) * Math.cos(fromLatRadians), Math.cos(distanceRadians)- Math.sin(fromLatRadians) * Math.sin(toLatRadians));
// adjust toLonRadians to be in the range -180 to +180...
toLonRadians = Math.IEEEremainder((toLonRadians + 3*M_PI), ((2*M_PI)) - M_PI);
Location result = new Location("");
result.setLatitude(rad2deg(toLatRadians));
result.setLongitude(rad2deg(toLonRadians));
return result;
}
double M_PI = 3.14159265358979323846264338327950288;
public double deg2rad(double degrees)
{
return (degrees * (M_PI/180));
}
public double rad2deg(double radians)
{
return (radians * (180/M_PI));
}