RectOut

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
ricardocrl
Posts: 117
Joined: 27 Dec 2010, 19:27

Re: RectOut

Post by ricardocrl »

I also noticed that the "width" and height" are not exactly right, considering my interpretation of the sizes. They are 1 pixel less then the actual size. If I as RectOut(0, 0, 4, 4) it will be a 5 x 5 square. Should that be corrected, or is there any reason for being like that?
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: RectOut

Post by mightor »

Let's count the pixels; 0, 1, 2, 3, 4 <-- that's 5 pixels :)

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: RectOut

Post by mattallen37 »

Yes, the bottom and left are sort of "free pixels".

I have been duplicating the FW drawing functions for use with BMP files. It has been a dilemma for me, trying to decide if I should do it like the FW, or logically. So far I have been doing it to match the FW.

@Xander, that's the point! it should be 4 pixels.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: RectOut

Post by HaWe »

actually not, Xander is right, it's just correct the way it currently is!
Imagine you have a fence with 5 fence posts in equal distance of 1 m:
| | | | |
between the first and last fence post is a distance (length) of 4m!

Imagine the fence posts are pixels, so if you have 5 pixels, then the distance (length) between the 1st and the 5th is 4 !
1 pixel does not define a line or a square but a point (elongation = 0 !) - the same way as 1 fence post does not define a line or a square but just a point (more or less),
4 pixels ( 2 in each dimension, wide and high) define the smallest thinkable square with a lenght =1 of each side (2 pixels each, vertices are counted twice!),

and if your square has a length and a heighth of 41 , then the number of pixels (or fence posts) on each side is...
Image
:!:

Amazing, isn't it ?
:D
Last edited by HaWe on 20 Mar 2012, 20:03, edited 1 time in total.
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: RectOut

Post by mightor »

Ah yes, they're not both absolute coordinates, my bad.

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: RectOut

Post by mattallen37 »

Helmut, I understand your logic, but I don't agree that it should be like that.

Anyhow, it's super easy to make wrap-up functions for anyone who wants it the other way. For compatibility reasons, I am 100% in favor of keeping it the way it is.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: RectOut

Post by HaWe »

that's not my logic, that's simply logical!

defining a rectangle, you have to define 1 start point (corner) and then you define the additional length and the height.
if you have 1 pixel as a start point (starting corner) and you add +1 for the length and +1 for the height you will get 1 more pixel at the right side of it and 1 more pixel directly above plus 1 pixel diagonally opposite = 4 pixels over all.

1 pixel corresponds to a point which has no area,
if you add +0 for the height (just 1 pixel "high") and +1 for the length (2 pixels side by side) you get a 2-pixel line (length=1), not a 1x2 rectangle.

Other way round:
the length between 2 cartesic coordinates is = sqrt (dx² + dy²)
end= (10,0)
start= (9,0)
length= sqrt ((10-9)² + 0²) = sqrt(1) = 1
so 2 pixels side by side (e.g., on 1 side of a rectangle) have a distance (length) of 1.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: RectOut

Post by mattallen37 »

doc-helmut wrote:...1 pixel corresponds to a point which has no area...
Right, I totally get it, but that's just not the way it appears.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: RectOut

Post by HaWe »

well, actually the reality never is ike it appears to be ;)

Imagine the pixels to be coordinates, not areas, then they will appear more to be what they actually are... :)

test it:
in your model, if you have 2 pixels above each other and also side by side: what will be your calculated diagonal length of that
::
square (distance from lower left to upper right)?
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: RectOut

Post by mattallen37 »

I totally and completely understand what you mean, and the logic you are using. I just personally see it the other way just as much.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 5 guests