I have a vertical slider that moves left to right intersecting the orange and red curves. Is it possible to put a small circle at the intersection of the rule and the curves?
This is the type of code I'd use but RuleMark has no idea where the intersection point is. Is there a command in SwiftUI which can accommodate this?
RuleMark(x: .value("Date", datesArray[Int(daySlider)].sunrise))
.foregroundStyle(Color.black)
.lineStyle(StrokeStyle(lineWidth: 1))
.symbol() {
Circle()
.fill(.orange)
.frame(width: 10)
}
Related
I want to draw an arc between point B to point D and it should touch to point E. ( I want to draw AND gate symbol )
I tried this way
QPainterPath path;
path.arcTo(60,30,46,100,30*16,120*16); // ( x,y,width,height, startAngle,spanAngle)
But it is drawing full circle and not in proper place.
Currently it is looking like this
After getting suggestion I tried like this :
path.moveTo(106, 80);
path.arcTo(76.0, 30.0, 60.0, 100.0, 90.0, -180.0);
How to get rid of that vertical line ( inside AND gate ) ?
Why it is appearing ?
I think you misunderstood the parameters for arcTo, especially the bounding rectangle.
Given your image, you should move path to (106, 80) (center of the bounding rectangle)
path.moveTo(106, 80);
The bounding rectangle of the arc should look like this:
x: 76
y: 30
width: 60
height: 100
The arc itsel should have a start angle at 90° and should span 180° in negative direction.
This results in:
path.arcTo(76.0, 30.0, 60.0, 100.0, 90.0, -180.0);
Update
arcTo
path.moveTo(106, 30);
path.cubicTo(QPointF(156.0, 30.0), QPointF(156.0, 130.0), QPointF(106.0, 130.0));
in my project i'm drawing a box over a an image using a custom drawing gesture.
Image(uiImage: image!)
.resizable()
.scaledToFit()
.onTouch(type:.all ,limitToBounds: true, perform: updateLocation) //custom touch
.overlay(
ForEach(paths) { container in
// draw the bounding box
container.path
.stroke(Color.red, lineWidth: 4)
}
)
my issue is the following:
when my image change the dimension to fit the view I want to scale up, or down the bounding box I draw in order to keep the same proportion.
before change change image scale:
after image scale up:
as you can see on the second screenshot when image frame become bigger the path draw on it change location a dimension.
How can I solve this issue?
I tried with the following code when the picture frame dimension change:
.onPreferenceChange(ViewRectKey.self) { rects in
pictureFrame = rects.first
// temp to aplly scale
guard let path = paths.last else {return}
paths.removeAll()
print("------------")
let pa = path.path.applying(CGAffineTransform(scaleX: 5, y: 5)) // 5 just for testing, need to use correct scale factor
let cont = PathContainer(id: UUID(), path: pa)
paths.append(cont)
}
but I don't know how to calculate how much the scale should be and second how to keep the position where initially I draw my path.
Cesium has various polyline materials (PolylineArrow, PolylineDash, PolylineGlow etc.) but
I want to draw a polyline consisting of lines that has an arrow in their head and an arrow in their center.
I think it can be done by adding GLSL code to PolylineArrowMaterial.
Only one idea that I have is adding section of polyline with arrow header instead on single polyline like this :
points.forEach((x, i) => {
if (i < points.length - 1) {
polylines.add({
positions: [points[i], points[i + 1]],
width: 12.0,
material: Cesium.Material.fromType('PolylineArrow', {
color: new Cesium.Color.fromBytes(255, 255, 0, 185)
})
});
}
});
I'm drawing different shapes with drawPolygon function. The following code snippet draws a hexagon as the picture shows (yes, it's partially transparent):
std::vector<Vec2> polyCoords = {
Vec2(75, 7),
Vec2(25, 7),
Vec2(0, 50),
Vec2(25, 93),
Vec2(75, 93),
Vec2(100, 50)
};
DrawNode* poly = DrawNode::create();
poly->setPosition(Vec2(500, 500));
poly->drawPolygon(polyCoords.data(), polyCoords.size(), Color4F(1,0,0,0.8), 10, Color4F(0,1,0,0.4));
As you can see the border is centered. I'd like to set the border to appear only outside the polygon area. It wouldn't be a problem if I were using solid colors, but in my case it's noticeable. Is there a way to remove the inner part of the border?
Is there any cocos2d function that returns the parent coordinate given a node local coordinate? It must be quite a common use case, but I've not found any native cocos2d function. Is there any?
I guess it's something like this. NOTE, I haven't tested this one. ;)
-(CGPoint) nodeToParent: (CGPoint) localPoint
{
CGFloat phi = -self.rotation * B2_pi / 180;
return ccpAdd(self.position, ccpRotateByAngle(localPoint, ccp(0, 0), phi));
}
As m.ding said ... parent->ConvertToNodeSpace() .....
Here's explanation for you so you know when to do what ?
convertToWorldSpace(const CCPoint& nodePoint) converts on-node coords to SCREEN coordinates.
Lets we have layerA with anchor point and position (0,0) attached to screen and have a sprite on this layer at point (100, 100).
What will be SCREEN coords of sprite? - (100, 100)
Lets we moved layerA to point (- 50, - 20). What will be SCREEN coords of sprite? - (100 - 50, 100 - 20), i.e. (50, 80) - that's what convertToWorldSpace returns to us if we call layerA->convertToWorldSpace(ccp(100, 100)).
As for convertToWorldSpaceAR - will return the position relatevely to anchor point: so if our scene - root layer has AP (0.5f, 0.5f) - default, convertToWorldSpaceAR should return position relatively to screen center. I have used convertToNodeSpace
convertToNodeSpace(const CCPoint& worldPoint) - converts SCREEN coords to NODE's local. I.e. if for our example with moved layer call:
layerA->convertToNodeSpace(ccp(50, 80)) - that should return (100, 100) - our sprite on-node coords.
convertToNodeSpaceAR - the same logic as for convertToWorldSpaceAR
assume your parent node is
CCSprite* parent;
you can use:
parent->convertToNodeSpace();
I guess that
-(CGPoint) convertToWorldSpace:(CGPoint)pt
could do the trick, take a look here.
It looks like you are on the right track. [node position] should give the position of the node in the parent's coordinate space, so if you have a local point that is offset from the [node position] then you need to do add the offset like you have done. I'm not sure the ccpRotateByAngle is the right method to do that but you'll just have to test it and find out!