I need help creating a wedge. I will know the radius, start rotation and end rotation. how can i create an arc/wedge?
Forum › How do I...?
HELP! Create a SVG wedge
Thanks.
The problem is that I only know the center point as well as the start and end rotation values. It looks like the arc command needs to know the points around the edge of the circle. Not sure of the formula to figure that out.
The problem is that I only know the center point as well as the start and end rotation values. It looks like the arc command needs to know the points around the edge of the circle. Not sure of the formula to figure that out.
If you know the centre point, the radius, and the start and end angles, you can find the start and end points of the arc like this:
Basic geometry, you just need to check a few things: what programming language are you using? Do the cos() and sin() functions expect degrees, or radians? Basic geometry.
start_x = centre_x + cos(start_angle)*radius
start_y = centre_y + sin(start_angle)*radius
end_x = centre_x + cos(end_angle)*radius
end_y = centre_y + sin(end_angle)*radius
Basic geometry, you just need to check a few things: what programming language are you using? Do the cos() and sin() functions expect degrees, or radians? Basic geometry.
Gotcha. My only problem now is that I'm trying to figure out how it all fits together. I'm doing the following:
The circle is skewed with how I've got it. Any ideas?
function drawWedge($xx, $yy, $rad, $startRot, $endRot, $inColor, $outColor, $outSize){
$startRot = $startRot;
$endRot = $endRot;
$startX = $xx + cos($startRot)*$rad;
$startY = $yy + sin($startRot)*$rad;
$endX = $xx + cos($endRot)*$rad;
$endY = $yy + sin($endRot)*$rad;
return '<path d="M'.$startX.','.$startY.' h'.$rad.' a'.$endX.','.$endY.' 0 1,0 '.$xx.','.$yy.' z" '.$inColor.' stroke="#'.$outColor.'" stroke-width="'.$outSize.'"; />'
}
The circle is skewed with how I've got it. Any ideas?
Can you paste some examples of input values and the SVG path you are getting as output? (Also, why does drawWedge begin with "$startRot = $startRot; isn't that redundant?)
Sorry about that. I was taking out this:
$startRot = norm($startRot);
etc.
It was a function to times the value by a percent (the scale percent). Don't worry about that part. That part is fine for all my shapes. Just need help with the wedge.
$startRot = norm($startRot);
etc.
It was a function to times the value by a percent (the scale percent). Don't worry about that part. That part is fine for all my shapes. Just need help with the wedge.