Rotate a graphic at a specific point
Rotate a graphic at a specific point
Rotate a graphic at a specific point
Rotate a graphic at a specific point
Rotate a graphic at a specific point
Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point
Rotate a graphic at a specific point Rotate a graphic at a specific point
Rotate a graphic at a specific point
Go Back  Xtreme Visual Basic Talk > > > Rotate a graphic at a specific point


Reply
 
Thread Tools Display Modes
  #1  
Old 12-10-2010, 12:42 AM
ashaan55 ashaan55 is offline
Newcomer
 
Join Date: Nov 2010
Location: MU
Posts: 15
Cool Rotate a graphic at a specific point


Hello guys, I want to rotate a graphic at a point and I used the centerX and centerY to define the center of rotation.
Here is what I wrote:

_____________________________________________________________
Dim rotate_mirror as new RotateTransform(CSng(txtbx_rotate_by.text))
rotate_mirror.centerX = 5
rotate_mirror.centery = 55
blk_mirror.RenderTransform = rotate_mirror
____________________________________________________________

blk_mirror is the graphic I want to rotate. Unfortunately, It does not work.

I learned about this on the following link:
HTML Code:
http://msdn.microsoft.com/en-us/library/system.windows.media.rotatetransform.aspx
When I copied the code in the above link and pasted it in the paint event, it didn't worked neither.
Can someone give me some clairification what's going on here?
Reply With Quote
  #2  
Old 12-10-2010, 09:00 AM
AtmaWeapon's Avatar
AtmaWeaponRotate a graphic at a specific point AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

As someone pointed out in the other thread, that class is a WPF class to be used in GUIs that use WPF. The Paint event is a Windows Forms concept, which leads me to believe you're using Windows Forms.

To do rotate transforms in WinForms, you have to have a graphics context, represented by the Graphics object. Its Transform property is set to a System.Drawing.Drawing2D.Matrix, which has helper methods like Rotate() if you aren't familiar with using matrices for affine transforms.

I'd have an example but a surprise meeting just sprung up; see if you can't get something accomplished by reading the documentation until then.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 12-13-2010, 08:11 AM
ashaan55 ashaan55 is offline
Newcomer
 
Join Date: Nov 2010
Location: MU
Posts: 15
Default

But with rotate() or rotatetransform, I cannot specify the point of rotation. For that , I got to translate it to the origin, rotae it and translate it back again. I don't want to mess into that unless I can't find any better way. Can you guys suggest something?
Reply With Quote
  #4  
Old 12-13-2010, 01:12 PM
passel's Avatar
passelRotate a graphic at a specific point passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Well, that is pretty much the way it has to be done. The rotation has to be mathematically around a zero point.
You can encapsulate the various calls necessary into a sub, so that from your application calls the sub with the parameters the way you prefer, and does the house keeping necessary within the sub to rotate around an arbitrary point.
I hope you realize you can't repeatedly modify an image directly because it will rapidly degrade. You need to keep the original image intact, calling the various graphics functions which will manipulate your transformation matrix, which will then map your drawing coordinates from an unrotated, unscaled coordinate system to the coordinate system specified by the state of transformation matrix.
For instance, if you have a compass image that you wish to rotate to show heading, you would have the original image, which you don't touch, and a drawing surface with you use the various graphics commands to setup any rotation, scaling, etc. and then use DrawImage to copy the original image to the drawing surface.

You don't necessarily have to "un"-translate.
If you need to do a series of graphic functions, but then want to return to an existing state, you can use BeginContainer and EndContainer, to contain the series of graphic commands which restores the state to what it was before you executed the BeginContainer.
Another option is to use Graphics.Save to save the state at a point, do a series of whatever drawing and manipulations, then Graphics.Restore, to restore the state back to what it was at the time you saved it.

I do have a rough project that I was initially using to play around with some of these capabilities, learning about it myself. A co-worker saw it and asked if they could do the same graphic stuff in C#. I said, since it was VB.net, then of course it could be done very similiarly in C#. But I hadn't done any C# at that point (only help someone else with general .net related questions in C#), so I did a more extensive and instructive project using C#, as both a learning exercise, and an example that I could pass on to others in my group who are more comfortable with C, than BASIC.
I haven't translated that C# project back into VB.Net, though, so don't have a reasonable VB project to provide as an example.
Also, since I'm new to .Net, there may be some bad programming practices in my code, but it is part of the learning process.

I guess I'll attach the early VB experimental code, as sloppy and incomplete as it is, as perhaps something might be learned from it, and it could be a starting project to play with.

I will also attach the C# project, which is more deliberately created as an example project, and I should port it to vb.net someday. The C# code duplicates the drawing subroutine. The normal drawing routine, just draws things as it is designed to do. The second routine has a large case structure, which breaks the drawing process into "steps".
It will progress through the drawing process down to the current "step" point, the exit out of the sub without doing the remaining steps. It displays a description of what it is doing at that step, including displaying the code being executed at that step. It draws a grid, which is not done in the normal drawing, so that the effect of rotation and scaling can be observed as to how it affects the coordinate system of the drawing at that step in the process.
I think it is a nice little example of an approach to solve some drawing needs I wanted to port from VB6, but again, it is my first attempts at this and I was learning as I went along so may not be the preferred approach.

Even if you don't have C#, looking at the code and maybe porting some of the things to vb.net might be useful. I haven't look at this in almost a year, so maybe this will be incentive for me to port the C# over to vb.net this upcoming holiday break.

I don't remember what all the buttons, and dragging options are.
If you see an unlabled 3-d bordered rectangle on the form (usally implemened with a picturebox, or panel), it is usally for dragging on to provide input to the program. Try dragging on them with both left, and right mouse buttons.
Also, dragging directly on the image, with left or right mouse buttons, may do things as well.

In the case of the C# code, I know the following,
Left button drag in the gray rectangle:
..Horizontally rotates the instrument.
..Vertically pitches the instrument.

Right button drag in the gray rectangle:
..Horizontally scales the image.

Left button drag in the picturebox (on the image).
..Moves the instrument around

Right button drag in the picturebox (on the image).
..Resizes the picturebox, horizontally or vertically.

These inputs work at all times, even when in the step mode, which is selected by pressing the checkbox next to the Prev button.
The reset button will reset all the scaling and instrument movement, and picturebox size back to their default initial values.

If you haven't installed C# express, you're going to miss out on some neat stuff, unless you want to try and port it to vb.net.

The code was done in Visual Studio 2005, but should upgrade to 2008 (and probably 2010), when loaded, without issue.

Note: The VB code in the next post is a port of the DrawStarsCS.zip C# code in this post, so is a better illustrative example than the DrawStarsVB.zip in this post. (just commenting since I see more access to the VB code in this post, but I think the code in the next post is more useful).
Attached Files
File Type: zip DrawStarsVB.zip (182.3 KB, 67 views)
File Type: zip DrawStarsCS.zip (132.7 KB, 18 views)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 06-06-2011 at 03:30 PM.
Reply With Quote
  #5  
Old 12-18-2010, 03:53 PM
passel's Avatar
passelRotate a graphic at a specific point passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

Well there has been 0 views to date on the C# version, so I spent a portion of today porting the C# example to VB.net (2005), so the more extensive example is available to persons who are strictly interested in VB.net

It is an unfinished start to another unused project, but modified to do the drawing two ways, as described above in the previous post.
If you select the Draw in Steps checkbox, all the inputs (dragging on the rectangle (picturebox) below the display area and on the display area itself), have the same effects they normally do, but since you use the prev/next buttons to select the step number, the drawing commands are processed up to that step, and then the following steps are skipped, so you can see the effect of the drawing commands in the order they occur.
In step mode, a grid is added so you can see the current coordinate orientation (which defines how your drawing coordiantes are mapped). A comment is added to the display area, describing what happens in that step, and the code executed at that "step" is displayed in a textbox below the display.

There is also a second page, incomplete, that displays a bitmap of gages, and an input area that rotates three needles around three of the gages, as just an example of a method to do that.

I don't remember what all the buttons, and dragging options are.
If you see an unlabled 3-d bordered rectangle on the form (usally implemened with a picturebox, or panel), it is usally for dragging on to provide input to the program. Try dragging on them with both left, and right mouse buttons.
Also, dragging directly on the image, with left or right mouse buttons, may do things as well.

Left button drag in the gray rectangle:
..Horizontally rotates the instrument.
..Vertically pitches the instrument.

Right button drag in the gray rectangle:
..Horizontally scales the image.

Left button drag in the picturebox (on the image).
..Moves the instrument around

Right button drag in the picturebox (on the image).
..Resizes the picturebox, horizontally or vertically.

These inputs work at all times, even when in the step mode, which is selected by pressing the checkbox next to the Prev button.
The reset button will reset all the scaling and instrument movement, and picturebox size back to their default initial values.
Attached Files
File Type: zip VB_Drawing_Demo.zip (101.4 KB, 101 views)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 12-03-2011 at 08:46 PM.
Reply With Quote
  #6  
Old 01-06-2011, 11:00 AM
ashaan55 ashaan55 is offline
Newcomer
 
Join Date: Nov 2010
Location: MU
Posts: 15
Cool

Sorry dude.. I changed my strategy.. I prefered to do the rotation using equations and it works pretty well. You can have a look of my up-to-date code at

Simulation Of a light Source and Mirrors...:)

Sure I'll welcome any comments you have..
Thanks
Ashaan
__________________
You Get In Life What You Have
The Courage To Ask For!

Last edited by ashaan55; 01-06-2011 at 11:09 AM.
Reply With Quote
  #7  
Old 01-14-2011, 04:34 PM
boops boops's Avatar
boops boops boops boops is offline
Centurion
 
Join Date: Dec 2006
Location: Holland and France
Posts: 146
Default

I'm surprised that after all the effort that has gone into this thread, nobody mentioned the Drawing2D.Matrix.RotateAt method which does precisely what the OP asked for:
Code:
Using mtx As New Drawing2D.Matrix
   mtx.RotateAt(angle,point)
   myGraphics.Transform = mtx
End Using
That will rotate anything drawn with the graphics object myGraphics by the specified angle in degrees around the given Point or PointF.

BB
Reply With Quote
Reply

Tags
aardvarks, centerx, centery, pt of rotation, rotatetransform, vague tags


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Rotate a graphic at a specific point
Rotate a graphic at a specific point
Rotate a graphic at a specific point Rotate a graphic at a specific point
Rotate a graphic at a specific point
Rotate a graphic at a specific point
Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point Rotate a graphic at a specific point
Rotate a graphic at a specific point
Rotate a graphic at a specific point
 
Rotate a graphic at a specific point
Rotate a graphic at a specific point
 
-->