Solved

need to scale a shape without losing information

Posted on 2006-11-06
11
196 Views
Last Modified: 2010-04-16
I have a list of points which define a shape
I need to shrink the shape
I know which direction to move the points
because if the angle is concave or convex
but sometimes if the points are too close to each other
they overlap and produce the wrong results

does anyone know of a good scaling algorithm that can avoid or compensate for this problem?
0
Comment
Question by:DangerMode
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
multiplying the coordinates of all the points by a constant will scale the shape
0
 

Author Comment

by:DangerMode
Comment Utility
It must be done on a point by point basis
A uniform scale doesnt preserve the original shape but it does keep it proportional.
Therefore when computing the new point based on a cross vector at certain angles if the scale is to big
the points overlap themselves.

0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Multiplying on a point by point basis is what I said.
A uniform scale preserves the original shape and keeps it proportional,
(which I thought were the same thing, unless you are using "shape" or "proportional" in a way I don't understand)
Points have 0 size, so the only way they can overlap is if they are the same point.
0
 
LVL 6

Expert Comment

by:_iskywalker_
Comment Utility
How do you interpolate the points? with splines? Maybe you should make an image of the image in normal mode, and then
scale it down (undersample, take for subsampling 2 times, every second pixel).
0
 
LVL 3

Expert Comment

by:Kipski
Comment Utility
I agree with ozo from what youv said...

Another way to do it would be to calculate or store the centre point of the shape and use this to determine the distance of each point in the shape boundary for which you have a reading from that point.  This way you could scale the shape by directly calculating the new size in proportion to its original position along the vector between it and the centre point.

It really depends on your original design and the complexity of the shapes you are drawing...

I created a shape drawing program, which deals with simple geometric forms such as squares, circles, triangles, diamonds and stars...  I treated each as a circle...

A square is a circle with only 4 points on its circumference recorded, a triangle has 3 points recorded... etc

The method I outlined for resizing worked well in this approach, proportionality was always maintained...  Rotating the shape was also simple...  
To draw the shape you just need the centre point, the radius or the circle and the angle of rotation, the draw method is identical regardless of the shape type, using these parameters, using oom

More complex shapes may require a different approach
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Expert Comment

by:Kipski
Comment Utility
To draw the shape you just need the centre point, the radius or the circle and the angle of rotation, the draw method is identical regardless of the shape type, using these parameters, using oom

And the number of points on the circumference....   Sorry...
0
 

Author Comment

by:DangerMode
Comment Utility
I apologize for not being able to articulate what I need, it is hard to say in words so I have created a couple pictures to show you.
Basically, I dont want uniform proportional scaling as that doesnt maintain a uniform distance away from the line. (contraction or erosion scaling) not sure the proper term for this either?
http://i121.photobucket.com/albums/o209/DangerMode/bad-vector.gif
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
Comment Utility
given points (x0,y0) (x1,y1) (x2,y2) in clockwise order, and constant distance d
A01 = y1-y0;
B01 = x0-x1;
A12 = y2-y1;
B12 = x1-x2;
C01 = A01*x0+B01*y0+d*sqrt(A01*A01+B01*B01);
C12 = A12*x1+B12*y1+d*sqrt(A12*A12+B12*B12);
Det=A01*B12-A12*B01;
newX1= (B12*C01-B01*C12)/Det;
newY1= (A01*C12-A12*C01)/Det;
0
 

Author Comment

by:DangerMode
Comment Utility
You are awesome finally someone who understands!
that is what I am doing

1) do you know the name of this algorithm, what would you call this?

So the problem arises when the distance is bigger then the point density and then points overlap
like in this case
http://i121.photobucket.com/albums/o209/DangerMode/vectorerr1.gif
(sorry the point numbers are upside down, but they show where the algorithm breaks down)

2) I thought of several approaches to fix it like removing those points and making a point at intersection etc
and all have other problems with them,
If you have any leads or ideas on how to fix this I would really really appreciated it.
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
It looks like you want to take the boundary defined by the black line (adding points were lines intersect) and eliminate all points contained inside that boundary. (using a non-zero or poitive winding number definition of inside)
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Here's how postscript defines different kinds of line joins
http://www.capcode.de/help/setlinejoin
http://www.capcode.de/help/setmiterlimit
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
changeXy challenge 13 56
array11 challenge 16 50
wordmultiple challenge 12 89
listing all functions in JavaScript 19 98
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now