This document is archived and information here might be outdated. Recommended version. |
ArcObjects namespaces > Geometry > ESRI.ArcGIS.Geometry > Interfaces > IA > IAffineTransformation2D3GEN Interface > IAffineTransformation2D3GEN.DefineFromControlPoints Method (ArcObjects .NET 10.4 SDK) |
Defines the best affine transformation between two sets of points. Can be used to register paper maps on a digitizer.
[Visual Basic .NET] Public Sub DefineFromControlPoints ( _ ByRef fromPoints As IPoint[], _ ByRef toPoints As IPoint[] _ )
[C#] public void DefineFromControlPoints ( ref IPoint[] fromPoints, ref IPoint[] toPoints );
[C++]
HRESULT DefineFromControlPoints(
Array* fromPoints,
Array* toPoints
);
[C++]
Parameters fromPoints [in] fromPoints is a parameter of type Array toPoints [in] toPoints is a parameter of type Array
//This example demonstrates how to use the IAffineTransformation2D3GEN.DefineFromControlPoints method
public void transformPolygon()
{
//From point
IPoint[] fromPoints=new IPoint[4];
fromPoints[0]=CreatePoint(0, 0);
fromPoints[1]=CreatePoint(0, 1);
fromPoints[2]=CreatePoint(1, 1);
fromPoints[3]=CreatePoint(1, 0);
//To point
IPoint[] toPoints=new IPoint[4];
toPoints[0]=CreatePoint(10, 10);
toPoints[1]=CreatePoint(10, 15);
toPoints[2]=CreatePoint(15, 15);
toPoints[3]=CreatePoint(15, 10);
//Create polygon
IGeometry segment1=CreateLineXY(0, 0, 0, 1) as IGeometry;
IGeometry segment2=CreateLineXY(0, 1, 1, 1) as IGeometry;
IGeometry segment3=CreateLineXY(0, 1, 0, 0) as IGeometry;
ISegmentCollection segmentCollection=new Polygon() as ISegmentCollection;
object Missing=Type.Missing;
segmentCollection.AddSegment(segment1 as ISegment, ref Missing, ref Missing);
segmentCollection.AddSegment(segment2 as ISegment, ref Missing, ref Missing);
segmentCollection.AddSegment(segment3 as ISegment, ref Missing, ref Missing);
IPolygon polygon=segmentCollection as IPolygon;
//Define the transformation
IAffineTransformation2D3GEN affineTransformation2D=new AffineTransformation2DClass();
affineTransformation2D.DefineFromControlPoints(ref fromPoints, ref toPoints);
//Transform
ITransform2D transform2D=polygon as ITransform2D;
transform2D.Transform(esriTransformDirection.esriTransformForward, affineTransformation2D as ITransformation);
}
private IPoint CreatePoint(double x, double y)
{
IPoint point=new ESRI.ArcGIS.Geometry.Point();
point.X=x;
point.Y=y;
return point;
}
public ILine CreateLineXY(double x1, double y1, double x2, double y2)
{
ILine line=new Line();
line.FromPoint=CreatePoint(x1, y1);
line.ToPoint=CreatePoint(x2, y2);
return line;
}
public ILine CreateLine(IPoint fromPoint, IPoint toPoint)
{
ILine line=new Line();
line.PutCoords(fromPoint, toPoint);
return line;
}
'This example demonstrates how to use the IAffineTransformation::DefineFromControlPoints method.
Public Sub AffTrans2D_DefFromPts()
'From point
Dim pPtFrom(0 To 3) As ESRI.ArcGIS.Geometry.IPoint
pPtFrom(0)=CreatePoint(0, 0)
pPtFrom(1)=CreatePoint(0, 1)
pPtFrom(2)=CreatePoint(1, 1)
pPtFrom(3)=CreatePoint(1, 0)
'To point
Dim pPtTo(0 To 3) As ESRI.ArcGIS.Geometry.IPoint
pPtTo(0)=CreatePoint(10, 10)
pPtTo(1)=CreatePoint(10, 15)
pPtTo(2)=CreatePoint(15, 15)
pPtTo(3)=CreatePoint(15, 10)
'Create polygon
Dim pSeg1 As ESRI.ArcGIS.Geometry.IGeometry
pSeg1=CreateLineXY(0, 0, 0, 1)
Dim pSeg2 As ESRI.ArcGIS.Geometry.IGeometry
pSeg2=CreateLineXY(0, 1, 1, 1)
Dim pSeg3 As ESRI.ArcGIS.Geometry.IGeometry
pSeg3=CreateLineXY(1, 1, 0, 0)
Dim pPolygon As ESRI.ArcGIS.Geometry.ISegmentCollection
pPolygon=New ESRI.ArcGIS.Geometry.Polygon
pPolygon.AddSegment(pSeg1)
pPolygon.AddSegment(pSeg2)
pPolygon.AddSegment(pSeg3)
Dim pPoly As ESRI.ArcGIS.Geometry.IPolygon
pPoly=pPolygon
'Define the transformation
Dim pAffineTrans2D As ESRI.ArcGIS.Geometry.IAffineTransformation2D3GEN
pAffineTrans2D=New ESRI.ArcGIS.Geometry.AffineTransformation2D
pAffineTrans2D.DefineFromControlPoints(pPtFrom, pPtTo)
Dim pTransform2d As ESRI.ArcGIS.Geometry.ITransform2D
'Transform
pTransform2d=pPolygon
pTransform2d.Transform(ESRI.ArcGIS.Geometry.esriTransformDirection.esriTransformForward, pAffineTrans2D)
End Sub
Public Function CreatePoint(ByVal XVal As Double, ByVal YVal As Double) As ESRI.ArcGIS.Geometry.IPoint
CreatePoint=New ESRI.ArcGIS.Geometry.Point
CreatePoint.X=XVal
CreatePoint.Y=YVal
End Function
Public Function CreateLineXY(ByVal X1 As Double, ByVal Y1 As Double, ByVal X2 As Double, ByVal Y2 As Double) As ESRI.ArcGIS.Geometry.ILine
CreateLineXY=CreateLine(CreatePoint(X1, Y1), CreatePoint(X2, Y2))
End Function
Public Function CreateLine(ByVal pPoint1 As ESRI.ArcGIS.Geometry.IPoint, ByVal pPoint2 As ESRI.ArcGIS.Geometry.IPoint) As ESRI.ArcGIS.Geometry.ILine
CreateLine=New ESRI.ArcGIS.Geometry.Line
CreateLine.PutCoords(pPoint1, pPoint2)
End Function