C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Rotating line inside rectangle bounds

By : user2185578
Date : November 22 2020, 04:01 AM
I wish this helpful for you Pseudocode to find intersection of ray emitted from rectangle center (with angle an in radians) with edges. (Works also for other (x0,y0) positions)
code :
``````x0 = width / 2;
y0 = height / 2;
vx = cos(an);
vy = sin(an);

//potential border positions
ex = vx > 0? width: 0
ey = vy > 0? height: 0

//check for horizontal/vertical directions
if vx = 0 then
return cx = x0,  cy = ey
if vy = 0 then
return cx = ex, cy = y0

//in general case find times of intersections with horizontal and vertical edge line
tx = (ex - x0) / vx
ty = (ey - y0) / vy

//and get intersection for smaller parameter value
if tx <= ty then
return cx = ex, cy = y0 + tx * vy
else
return cx = x0 + ty * vx,  cy = ey
``````

Share :

## How to draw rounded rectangle with variable width border inside of specific bounds

By : Saikano
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Alright guys, I figured it out! Just need to shrink the bounds to take into account the width of the pen. I kind of knew this was the answer I was just wondering if there was a way to draw a line on the inside of a path. This works good though.
code :
``````private void DrawRoundedRectangle(Graphics gfx, Rectangle Bounds, int CornerRadius, Pen DrawPen, Color FillColor)
{
int strokeOffset = Convert.ToInt32(Math.Ceiling(DrawPen.Width));
Bounds = Rectangle.Inflate(Bounds, -strokeOffset, -strokeOffset);

DrawPen.EndCap = DrawPen.StartCap = LineCap.Round;

GraphicsPath gfxPath = new GraphicsPath();
gfxPath.CloseAllFigures();

gfx.FillPath(new SolidBrush(FillColor), gfxPath);
gfx.DrawPath(DrawPen, gfxPath);
}
``````

## Rotating Several points inside rectangle

By : Cuty
Date : March 29 2020, 07:55 AM
To fix this issue Your y-rotation uses modified x-value, but you need to use the base value - use a temporary variable, like this:
code :
``````double x_tmp = round((rstruct2->xcol[tc]-160)*cos(theta1)-sin(theta1)*(rstruct2->ycol[tc]-240)+160);
double y_tmp = round((rstruct2->xcol[tc]-160)*sin(theta1)+cos(theta1)*(rstruct2->ycol[tc]-240)+240);

rstruct2->xcol[tc] = x_tmp;
rstruct2->ycol[tc] = y_tmp;
``````

## Can I use the Postgres functions to find points inside a rotating rectangle of fixed size?

By : M.anes
Date : March 29 2020, 07:55 AM
I hope this helps . I ended up by generating rectangle vertices, rotating those vertices, and then comparing the area of the rectangle (constant) with the area of the 4 triangles that are made by including the test point.
This technique is based on the parsimonious answer:
code :
``````with t as (select 10*0.5 as x, 20*0.5 as y, 17.0 as qx, -3.0 as qy)

select
z.angle
-- ABC area
--,abs(0.5*(z.ax*(z.by-z.cy)+z.bx*(z.cy-z.ay)+z.cx*(z.ay-z.by)))

-- CDA area
--,abs(0.5*(z.cx*(z.dy-z.ay)+z.dx*(z.ay-z.cy)+z.ax*(z.cy-z.dy)))

-- ABCD area
,abs(0.5*(z.ax*(z.by-z.cy)+z.bx*(z.cy-z.ay)+z.cx*(z.ay-z.by))) + abs(0.5*(z.cx*(z.dy-z.ay)+z.dx*(z.ay-z.cy)+z.ax*(z.cy-z.dy))) as abcd_area

-- ABQ area
--,abs(0.5*(z.ax*(z.by-z.qx)+z.bx*(z.qy-z.ay)+z.qx*(z.ay-z.by)))

-- BCQ area
--,abs(0.5*(z.bx*(z.cy-z.qx)+z.cx*(z.qy-z.by)+z.qx*(z.by-z.cy)))

-- CDQ area
--,abs(0.5*(z.cx*(z.dy-z.qx)+z.dx*(z.qy-z.cy)+z.qx*(z.cy-z.dy)))

-- DAQ area
--,abs(0.5*(z.dx*(z.ay-z.qx)+z.ax*(z.qy-z.dy)+z.qx*(z.dy-z.ay)))

-- total area of triangles with question point (ABQ + BCQ + CDQ + DAQ)
,abs(0.5*(z.ax*(z.by-z.qx)+z.bx*(z.qy-z.ay)+z.qx*(z.ay-z.by)))
+ abs(0.5*(z.bx*(z.cy-z.qx)+z.cx*(z.qy-z.by)+z.qx*(z.by-z.cy)))
+ abs(0.5*(z.cx*(z.dy-z.qx)+z.dx*(z.qy-z.cy)+z.qx*(z.cy-z.dy)))
+ abs(0.5*(z.dx*(z.ay-z.qx)+z.ax*(z.qy-z.dy)+z.qx*(z.dy-z.ay))) as point_area

from
(
SELECT
a.id as angle
-- bottom left (A)
--top left (B)
--top right (C)
--bottom right (D)

-- point to check (Q)
,t.qx as qx
,t.qy as qy
FROM generate_series(0,180,10) AS a(id), t
) z
;
``````
``````angle;abcd_area;point_area
0;200;340
10;200;360.6646055963
20;200;373.409049054212
30;200;377.846096908265
40;200;373.84093170467
50;200;361.515248361426
60;200;341.243556529821
70;200;313.641801308188
80;200;279.548648061772
90;200;240
*100;200;200*
*110;200;200*
*120;200;200*
*130;200;200*
*140;200;200*
150;200;237.846096908265
160;200;277.643408923024
170;200;312.04311584956
180;200;340
``````

## A ball rotating inside a rectangle, a QML project

By : Pravkulk
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I have a ball animating inside a Rectangle in a QML project as below and want that when it hits the borders of the Rectangle it returns back to the inside until it hits another border, then it backs again, an so on. , Very simple implementation of bouncing ball:
code :
``````Rectangle {
id: container
anchors.fill: parent
border.color: "orange"
border.width: 3

Rectangle {
id: ball
property double xincrement: Math.random() + 0.5
property double yincrement: Math.random() + 0.5
width: 50
height: width
color: "lightgreen"
x: 300
y: 300

Timer {
interval: 1
repeat: true
running: true
onTriggered: {
ball.x = ball.x + (ball.xincrement * 2.0);
ball.y = ball.y + (ball.yincrement * 2.0);
if(ball.x <= 0 || ball.x + ball.width >= container.width)
ball.xincrement *= (-1);
if(ball.y <= 0 || ball.y + ball.height >= container.height)
ball.yincrement *= (-1);
}
}

}
}
``````

## java - keep painted rectangle inside JPanel bounds when user paints

By : chufla87
Date : March 29 2020, 07:55 AM
will help you In your MouseMotionListener, mouseDragged method, check to see if the mouse's Point is outside of the bounds of your JPanel, and then respond accordingly if it is.