We have a LOT of experience with this, since our DD was around the same age and had terrible problems with pooing. Tell me if any of this sounds familiar:
She seems extremely irritable, won't sit down, farts constantly, and will suddenly get very, very agitated (probably because she needs a poo but holds on for fear of the pain) and in general it's a massive issue for her. You're worried, understandably, and you're extremely focused on this issue.
Here is what we went through:
We tried our GP, who recommended something called Movicol and also Sennacot and Lactulose (sp?). Movicol makes them poop, but it softens the poop up hugely and basically they poo all the time. When they've been on Movicol a while get ready for just constant pooing all day. Sennacot is meant to make them regular, but in my opinion it does fuck all. Lactulose I didn't see have much effect either.
After a long time faffing around with this, and I am talking months, I found a few things myself. Orange juice, olives - those two things almost always guaranteed a poo that evening or even sooner. She wasn't happy about it in either case, but she did it. As you describe it, laying on her back, screaming, "delivering a baby" style pooing. It's horrible and heart breaking but she was then a pleasure to be around for the next few days.
Every time we went, we were effusive with our praise. "Oh well done! You did a poo! Fantastic!" and also went through the whole tearful begging/pleading/reasoning/reward chart experience.
I am not saying those things won't work, but here is what worked for us..
- Stop making an issue of it. Literally IGNORE the fact she is not pooing. Obviously, you're still concerned and I know it's hard, but here is WHY you make no big issue of it. As long as you focus on this pooing thing, she is in control. One of the reasons she gets so angry is because she is in pain, but the other reason is that she is losing control. Rewarding her/praising her is bringing more attention to the fact that this is something SHE has control over. And her giving you a poo is still her decision. It's not, of course, it's something she has to do. It needs to be no big deal.
- Nappies. This was the turning point for us. Once we got away from nappies, everything became so much easier. Imagine pooing in a nappy - it's horrible, right? Why would SHE want to do it? This can just be one of those things they go through before toilet training. It's kind of messed up to imagine as a child that suddenly you are aware of things COMING OUT OF YOUR BODY! And you have no control over that. No wonder they freak out.
- This will end. Soon your child will be fine. No matter how badly ripped up her bum used to get, for some miraculous reason some Sudocrem and a cuddle fixed it well enough. She's absolutely good as gold now at 4, and takes herself off for a wee or a poo without any trouble at all.
I know this is tough, and it really doesn't seem to make any sense, but you need to be very clever about it.