This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
undead80  
#1 Posted : Friday, January 11, 2008 9:55:56 AM(UTC)
undead80

Rank: Member

Groups: Guest
Joined: 1/7/2008(UTC)
Posts: 28

Hi,

I need to create a new VObject which clone another VObject Rotation Angle, and Location.

Was trying with

Code:
        Dim Trans As System.Drawing.Drawing2D.Matrix = CType(orgObj.Transform.Clone, System.Drawing.Drawing2D.Matrix)

        Dim newObj As Aurigma.GraphicsMill.WinControls.ImageVObject = New Aurigma.GraphicsMill.WinControls.ImageVObject(image, True, 0, 0)

        newObj.Transform = Trans 



This code work perfect if the orgObj is not being resized. As I only want the new VObject copy the old VObject roration angle, and also the location , but not any others. Please advice.

I manage to copy the location by
Code:
        Dim newObj As Aurigma.GraphicsMill.WinControls.ImageVObject = New Aurigma.GraphicsMill.WinControls.ImageVObject(image, True, Trans.X, Trans.Y)



But no luck on the rotation. Please advice.

Edited by user Sunday, January 13, 2008 2:25:57 AM(UTC)  | Reason: Not specified

Alex Kon  
#2 Posted : Wednesday, January 16, 2008 9:18:27 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups: Guest
Joined: 1/31/2005(UTC)
Posts: 458

Was thanked: 5 time(s) in 5 post(s)
Hello,

I'm afraid that you will need more code to implement this... ;) Here is sample which calculates rotation angle and dimensions of the object.

First of all main code - it creates RectangleVObject which has same parameters as some another rectangular object (let it be "srcObj"):

Code:
//
// Get rotation angle and size of the srcObj
//
System.Drawing.PointF[] topSide;
GetTransformedTopSide(srcObj,  out topSide);
float angle = CalcAngle(
	new System.Drawing.PointF(1000, 0) /*horizontal vector*/,
	new System.Drawing.PointF(/*vector of the top-side of the srcObj*/
		topSide[1].X - topSide[0].X, 
		topSide[1].Y - topSide[0].Y));

SizeF srcObjSize = GetTransformedDimensions(srcObj);

//
//Create new RectangleVObject 
//
Aurigma.GraphicsMill.WinControls.RectangleVObject newObj = 
	new Aurigma.GraphicsMill.WinControls.RectangleVObject(
		0,
		0,
		dstSize.Width, 
		dstSize.Height);

newObj.Transform.Rotate(
	angle, 
	System.Drawing.Drawing2D.MatrixOrder.Append);
newObj.Transform.Translate(
	topSide[0].X, 
	topSide[0].Y, 
	System.Drawing.Drawing2D.MatrixOrder.Append);

//
// Add created object to the viewer control
//
multiLayerViewer.CurrentLayer.VObjects.Add(newObj);


The code above uses folowing methods:

Code:
//
// Calculates angle between 2 specified vectors.
//
private static float CalcAngle(
	System.Drawing.PointF v0, 
	System.Drawing.PointF v1)
{
	float dotProduct = v0.X * v1.X + v0.Y + v1.Y;
	float vLengthProduct = CalcLength(v0) * CalcLength(v1);

	if (vLengthProduct < 0.01)
		throw new ApplicationException("Ups, div by zero error...");

	float result = 
		(float)(Math.Acos(dotProduct / vLengthProduct) / Math.PI * 180);

	float vecProduct = v0.X * v1.Y - v0.Y * v1.X;
	if (vecProduct < 0)
		result = 360 - result;
	
	return result;
}


//
// Returns coordinates of the top side of the specified rectangular
// object. side[0] - is the coordinates of the left-top corner in
// original image, side[1] - right-top corner.
//
private static void GetTransformedTopSide(
	Aurigma.GraphicsMill.WinControls.IVObject obj, 
	out System.Drawing.PointF[] side)
{
	System.Drawing.RectangleF baseRect = obj.GetVObjectBounds();
	System.Drawing.PointF[] points = new System.Drawing.PointF[2];
	points[0] = baseRect.Location;
	points[1] = 
		new System.Drawing.PointF(baseRect.Right, baseRect.Top);

	obj.Transform.TransformPoints(points);
	side = points;
}


//
// Returns dimensions (width and height) of the 
// transformed object. 
// 
private static System.Drawing.SizeF GetTransformedDimensions(
	Aurigma.GraphicsMill.WinControls.IVObject obj)
{
	System.Drawing.RectangleF baseRect = obj.GetVObjectBounds();
	System.Drawing.PointF[] cornerPnts = new System.Drawing.PointF[3];
	
	cornerPnts[0] = baseRect.Location;
	cornerPnts[1] = 
		new System.Drawing.PointF(baseRect.Right, baseRect.Top);
	cornerPnts[2] = 
		new System.Drawing.PointF(baseRect.Left, baseRect.Bottom);
	
	obj.Transform.TransformPoints(cornerPnts);

	return new System.Drawing.SizeF(
		CalcDistance(cornerPnts[0], cornerPnts[1]),
		CalcDistance(cornerPnts[0], cornerPnts[2]));
}


//
// Calculates distance between 2 points.
//
private static float CalcDistance(
	System.Drawing.PointF p0, 
	System.Drawing.PointF p1)
{
	float dx = p0.X - p1.X;
	float dy = p0.Y - p1.Y;
	return (float)Math.Sqrt(dx * dx + dy * dy);
}


//
// Calculates length of the specified vector.
//
private static float CalcLength(System.Drawing.PointF v0)
{
	return (float)Math.Sqrt(v0.X * v0.X + v0.Y * v0.Y);
}

Emerson Sepia  
#3 Posted : Tuesday, May 5, 2009 3:54:51 AM(UTC)
Emerson Sepia

Rank: Newbie

Groups: Guest
Joined: 4/28/2009(UTC)
Posts: 9

How useful was for me and I had to translate to VB.NET, then put my code here and can be
more useful to someone.

Code:
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ''
        '' Get rotation angle and size of the srcObj
        ''
        Dim topSide As System.Drawing.PointF()
        topSide = GetTransformedTopSide(RetornObjetoSelecionado)
        Dim angle As Single = CalcAngle(New System.Drawing.PointF(1000, 0), New System.Drawing.PointF( _
                    topSide(1).X - topSide(0).X, _
                    topSide(1).Y - topSide(0).Y))

        Dim srcObjSize As SizeF = GetTransformedDimensions(RetornObjetoSelecionado)

        ''
        ''Create new RectangleVObject 
        ''
        Dim newObj As Aurigma.GraphicsMill.WinControls.RectangleVObject = _
         New Aurigma.GraphicsMill.WinControls.RectangleVObject(0, 0, srcObjSize.Width, srcObjSize.Height)


        newObj.Transform.Rotate(angle, System.Drawing.Drawing2D.MatrixOrder.Append)
        newObj.Transform.Translate(topSide(0).X, topSide(0).Y, System.Drawing.Drawing2D.MatrixOrder.Append)

        ''
        '' Add created object to the viewer control
        ''
        canvas.CurrentLayer.VObjects.Add(newObj)
    End Sub

 ''' <summary>
    ''' Calculates distance between 2 points.
    ''' </summary>
    ''' <param name="p0"></param>
    ''' <param name="p1"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function CalcDistance( _
           ByVal p0 As System.Drawing.PointF, _
           ByVal p1 As System.Drawing.PointF) As Single

        Dim dx As Single = p0.X - p1.X
        Dim dy As Single = p0.Y - p1.Y
        Return Math.Sqrt(dx * dx + dy * dy)
    End Function
    ''' <summary>
    ''' Calculates length of the specified vector.
    ''' </summary>
    ''' <param name="v0"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function CalcLength(ByVal v0 As System.Drawing.PointF) As Single
        Return Math.Sqrt(v0.X * v0.X + v0.Y * v0.Y)
    End Function

 
    ''' <summary>
    ''' Returns dimensions (width and height) of the 
    ''' transformed object. 
    ''' </summary>
    ''' <param name="obj"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetTransformedDimensions(ByVal obj As Aurigma.GraphicsMill.WinControls.IVObject) As System.Drawing.SizeF
 
        Dim baseRect As System.Drawing.RectangleF = obj.GetVObjectBounds()

        Dim cornerPnts As System.Drawing.PointF() = New System.Drawing.PointF(2) {}


        cornerPnts(0) = baseRect.Location
        cornerPnts(1) = New System.Drawing.PointF(baseRect.Right, baseRect.Top)
        cornerPnts(2) = New System.Drawing.PointF(baseRect.Left, baseRect.Bottom)

        obj.Transform.TransformPoints(cornerPnts)

        Return New System.Drawing.SizeF(CalcDistance(cornerPnts(0), cornerPnts(1)), CalcDistance(cornerPnts(0), cornerPnts(2)))
    End Function



    ''' <summary>
    ''' Returns coordinates of the top side of the specified rectangular
    ''' object. side[0] - is the coordinates of the left-top corner in
    ''' original image, side[1] - right-top corner.
    ''' </summary>
    ''' <param name="obj"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetTransformedTopSide(ByVal obj As Aurigma.GraphicsMill.WinControls.IVObject) As System.Drawing.PointF()

        Dim baseRect As System.Drawing.RectangleF = obj.GetVObjectBounds()
        Dim points As System.Drawing.PointF() = New System.Drawing.PointF(1) {}


        points(0) = baseRect.Location
        points(1) = New System.Drawing.PointF(baseRect.Right, baseRect.Top)

        obj.Transform.TransformPoints(points)
        Return points
    End Function



    ''' <summary>
    ''' Calculates angle between 2 specified vectors.
    ''' </summary>
    ''' <param name="v0"></param>
    ''' <param name="v1"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function CalcAngle(ByVal v0 As System.Drawing.PointF,      ByVal v1 As System.Drawing.PointF) As Single

        Dim dotProduct As Single = v0.X * v1.X + v0.Y + v1.Y
        Dim vLengthProduct As Single = CalcLength(v0) * CalcLength(v1)

        If (vLengthProduct < 0.01) Then Throw New ApplicationException("Ups, div by zero error...")

        Dim result As Single = (Math.Acos(dotProduct / vLengthProduct) / Math.PI * 180)

        Dim vecProduct As Single = v0.X * v1.Y - v0.Y * v1.X
        If (vecProduct < 0) Then result = 360 - result
        Return result
    End Function

Users browsing this topic
Guest (3)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.