affinetransform

How to Rotate AWT rectangle in JAVA?

我的梦境 提交于 2019-12-11 12:03:17
问题 I am creating a small java 2D game and i want to know if there is any way to rotate AWT rectangle AffineTransform origXform = g2d.getTransform(); AffineTransform newXform = (AffineTransform) origXform.clone(); newXform.rotate(angle, pivotX, pivotY); // pivotX ,pivotY is the starting point of the hand image g2d.setTransform(newXform); Rectangle arm = new Rectangle(bowX + 5, bowY + 55, 60, 5); g2d.drawImage(playerBowReadyImg, bowX, bowY, null); //hand image on the above code i simply draw the

How can same calculation produce different results

北城余情 提交于 2019-12-11 09:39:05
问题 Just spend two hours debugging this, I think I know the cause of the problem but I don't understand how can it produce the kind of results it does. I've got a Swing based application where I override JPanel.paint(Graphics g) like this public void paint(Graphics g) { <snipped code> Insets is = getInsets(); Dimension sz = getSize(); g2.setClip(is.left + 1, is.top + 1, sz.width - is.right - is.left - 2, sz.height - is.top - is.bottom - 2); int w = getWidth(); int h = getHeight(); double s = Math

Generate AffineTransform from 3 points

半城伤御伤魂 提交于 2019-12-11 05:08:34
问题 Given 3 points (x and y coordinates) in coordinate system A, and 3 corresponding points in coordinate system B, how can I derive an AffineTransform that will convert from A to B. My question is similar to Create transform to map from one rectangle to another?, except that question only deals with 2 points - i.e., it assumes there is no rotation. 回答1: Suppose your transform is of the form x' = px + qy + r y' = sx + ty + u and write your six points as (A1x, A1y), (A2x, A2y), (A3x, A3y), (B1x,

How can I draw on JPanel using another quadrant for the coordinates?

别来无恙 提交于 2019-12-08 10:56:20
问题 I would like to draw some shapes on a JPanel by overriding paintComponent . I would like to be able to pan and zoom. Panning and zooming is easy to do with AffineTransform and the setTransform method on the Graphics2D object. After doing that I can easyli draw the shapes with g2.draw(myShape) The shapes are defined with the "world coordinates" so it works fine when panning and I have to translate them to the canvas/JPanel coordinates before drawing. Now I would like to change the quadrant of

Proportional Translation

只谈情不闲聊 提交于 2019-12-08 08:24:23
问题 I'd like to update a list of points (PointFs) by performing a rotation (around a new origin) and translating each point by an amount that is proportional to its current distance from the origin (so not an absolute translation). I currently do this for each point in turn but performance is poor when moving more than a handful of points. I'd like to make the transformation more efficient so wanted to use a matrix. The rotation is no problem, but I don't know how to do the proportional

Zoom in with affinetransform swing

不打扰是莪最后的温柔 提交于 2019-12-07 19:39:39
问题 I'm working on my personal project using JAVA swing. The project is about drawing a map on a window. The map is zoomable using affinetransform. The problem I'm having here is whenever I zoom in or out the map also shifts instead of zooming in/out on the point of the map that is at the center of the screen private void updateAT() { Dimension d = panel.getSize(); int panelW = d.width; int panelH = d.height; Rectangle2D r = regionList[0].get("Victoria").getShape().getBounds2D(); scaleX = (panelW

Proportional Translation

独自空忆成欢 提交于 2019-12-07 00:50:32
I'd like to update a list of points (PointFs) by performing a rotation (around a new origin) and translating each point by an amount that is proportional to its current distance from the origin (so not an absolute translation). I currently do this for each point in turn but performance is poor when moving more than a handful of points. I'd like to make the transformation more efficient so wanted to use a matrix. The rotation is no problem, but I don't know how to do the proportional translation. Can I do this with an affine matrix? Is there some other way to do the transformation more

Matlab calculate 3D similarity transformation. fitgeotrans for 3D

雨燕双飞 提交于 2019-12-06 15:27:51
How can I calculate in MatLab similarity transformation between 4 points in 3D? I can calculate transform matrix from T*X = Xp , but it will give me affine matrix due to small errors in points coordinates. How can I fit that matrix to similarity one? I need something like fitgeotrans , but in 3D Thanks The answer by @rayryeng is correct, given that you have a set of up to 3 points in a 3-dimensional space. If you need to transform m points in n-dimensional space ( m>n ), then you first need to add m-n coordinates to these m points such that they exist in m-dimensional space (i.e. the a matrix

Zoom in with affinetransform swing

徘徊边缘 提交于 2019-12-06 11:21:52
I'm working on my personal project using JAVA swing. The project is about drawing a map on a window. The map is zoomable using affinetransform. The problem I'm having here is whenever I zoom in or out the map also shifts instead of zooming in/out on the point of the map that is at the center of the screen private void updateAT() { Dimension d = panel.getSize(); int panelW = d.width; int panelH = d.height; Rectangle2D r = regionList[0].get("Victoria").getShape().getBounds2D(); scaleX = (panelW/r.getWidth()) * zoom; scaleY = (panelH/r.getHeight()) * zoom; AffineTransform goToOrigin =

java rotate rectangle around the center

大兔子大兔子 提交于 2019-12-05 08:04:41
I would like to rotate a rectangle around its center point and it should remain in the place that it is supposed be drawn and rotate in that space this is my code: AffineTransform transform = new AffineTransform(); transform.rotate(Math.toRadians(45),rectangle.width/2, rectangle.height/2); Shape transformed = transform.createTransformedShape(rectangle); g2.fill(transformed) the rectangle is rotated but it is drawn at a different part of the screen, how can I correct this? I haven't tried this, but it seems you aren't getting the correct middle of the rectangle. Try: AffineTransform transform =