Help with Draw.Arc formula
Author |
Message |
Danjen
|
Posted: Wed Dec 20, 2006 2:36 pm Post subject: Help with Draw.Arc formula |
|
|
I am trying to make a program that will be able to draw a multi-sided shape (like Draw.Polygon), but instead of connecting it with straight lines, I wanted to connect them with a smooth arc.
What I have so far:
code: |
const Maxdot : int := 6 %%Num of sides
const MAXX : int := maxx div 2 %%Middle of X-axis
const MAXY : int := maxy div 2 %%Middle of Y-axis
%%Calculates the average of an array; used to find middle of shape
fcn CalcAvg (x : array 1 .. Maxdot of real, rangeMin, rangeMax : int) : real
var sum : real := 0
for i : rangeMin .. rangeMax
sum += x (i)
end for
sum /= ((rangeMax - rangeMin) + 1)
result sum
end CalcAvg
%%The data for the vertices and midpoint
var Dot :
record
X : array 1 .. Maxdot of real
Y : array 1 .. Maxdot of real
MidX : real
MidY : real
end record
%%Makes the shape in a hexagon
Dot.X (1) := MAXX - 50
Dot.Y (1) := MAXY
Dot.X (2) := MAXX - 25
Dot.Y (2) := MAXY + 25
Dot.X (3) := MAXX + 25
Dot.Y (3) := MAXY + 25
Dot.X (4) := MAXX + 50
Dot.Y (4) := MAXY
Dot.X (5) := MAXX + 25
Dot.Y (5) := MAXY - 25
Dot.X (6) := MAXX - 25
Dot.Y (6) := MAXY - 25
%%Calculates the midpoint of shape
Dot.MidX := CalcAvg (Dot.X, 1, Maxdot)
Dot.MidY := CalcAvg (Dot.Y, 1, Maxdot)
%%Displays numeric value and graphic of midpoint (for debugging purposes)
put "(", Dot.MidX, ",", Dot.MidY, ")"
Draw.Oval (round (Dot.MidX), round (Dot.MidY), 2, 2, 7)
for i : 1 .. Maxdot
Draw.FillOval (round (Dot.X (i)), round (Dot.Y (i)), 1, 1, 7) %%Draws each verice, again for debugging purposes
if i not= 1 then
Draw.Arc (
round ((Dot.X (i) + Dot.X (i - 1) + Dot.MidX) / 3),
round ((Dot.Y (i) + Dot.Y (i - 1) + Dot.MidY) / 3),
round (max (Dot.MidX - ((Dot.X (i) + Dot.X (i - 1) + Dot.MidX) / 3), ((Dot.X (i) + Dot.X (i - 1) + Dot.MidX) / 3) - Dot.MidX)),
round (max (Dot.MidY - ((Dot.Y (i) + Dot.Y (i - 1) + Dot.MidY) / 3), ((Dot.Y (i) + Dot.Y (i - 1) + Dot.MidY) / 3) - Dot.MidY)),
0,
45,
7)
end if
end for
|
But the problem is with this chunk here:
code: |
Draw.Arc (
round ((Dot.X (i) + Dot.X (i - 1) + Dot.MidX) / 3),
%%Calculates the value of X; the average between vertice 1, 2, and the midpoint of the shape.
round ((Dot.Y (i) + Dot.Y (i - 1) + Dot.MidY) / 3),
%%Calculates the value of Y; the average between vertice 1, 2, and the midpoint of the shape.
%%The problem lies in here I think:
round (max (Dot.MidX - ((Dot.X (i) + Dot.X (i - 1) + Dot.MidX) / 3), ((Dot.X (i) + Dot.X (i - 1) + Dot.MidX) / 3) - Dot.MidX)),
%%Calculates the average of vertices 1, 2, and the midpoint to get a value, then determines the difference between it and the midpoint, to get a specific size of the radius. If the number is negative, it will make it positive.
round (max (Dot.MidY - ((Dot.Y (i) + Dot.Y (i - 1) + Dot.MidY) / 3), ((Dot.Y (i) + Dot.Y (i - 1) + Dot.MidY) / 3) - Dot.MidY)),
%%The same, but for the Y value.
%%Angles and color just set to an arbitrary amount for testing
0,
45,
7)
|
The problem is that when i = 3, 4, or 5, the arc doesn't show up. When I change Dot.X(2) := MAXX - 25 to -37, they all show up, albeit in a scrunched manner. Plz help? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|